获取数字范围:
range()
在python3.x中使用range():
1 >>> list(range(7)) 2 [0, 1, 2, 3, 4, 5, 6] 3 >>> for i in range(6): 4 print(i) 5 6 0 7 1 8 2 9 3 10 4 11 5 12 >>>
continue ---调到下一个列表项
break ---跳出循环
1 >>> numbers 2 [1, 2, 3, 4, 5, 6] 3 >>> for i in numbers: 4 if i == 3: 5 print(‘跳过当前‘) 6 continue 7 print(i) 8 9 1 10 2 11 跳过当前 12 4 13 5 14 6 15 >>>
1 >>> numbers = list(range(7)) 2 >>> numbers 3 [0, 1, 2, 3, 4, 5, 6] 4 >>> for i in numbers : 5 print(i) 6 if i > 4: 7 print(‘执行到此,后面不执行‘) 8 break 9 10 0 11 1 12 2 13 3 14 4 15 5 16 执行到此,后面不执行 17 >>>
时间: 2024-10-13 06:54:46