獲取數字範圍:python
range()python3.x
在python3.x中使用range():spa
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 ---調到下一個列表項code
break ---跳出循環blog
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 >>>