python如何知道何时停止for循环?

时间:2018-05-07 15:05:05

标签: loops for-loop while-loop infinite-loop

python中的第一次编程python如何知道何时停止for循环? 喜欢的for没有匹配的结尾对吗?那怎么知道什么是循环的一部分,什么不是? 抱歉,如果这是一个愚蠢的问题,我找不到答案

1 个答案:

答案 0 :(得分:1)

Python在很大程度上依赖于缩进

# Below prints 1-5, sees that the next for line is not indented, doesn't read it
for x in range(5):
    print(x)

# there are other methods of breaking a python loop
for x in range(6):
    print(x)
 if x == 5:
         # break the loop
         break