用for遍历整个列表 >>> cells =['cellA', 'cellB', 'cellC', 'cellD']
>>> for cel in cells:
... print(cel)
...
cellA
cellB
cellC
cellD
For循环中加入操作 >>> cells =['cellA', 'cellB', 'cellC', 'cellD']
>>> for cel in cells:
... print('cells list include ' + cel + '.')
...
cells list include cellA.
cells list include cellB.
cells list include cellC.
cells list include cellD.
For循环后加入操作 >>> cells =['cellA', 'cellB', 'cellC', 'cellD']
>>> for cel in cells:
... print('cells list include ' + cel + '.')
...
>>> print('that is all cells')
cells list include cellA.
cells list include cellB.
cells list include cellC.
cells list include cellD.
that is all cells
For循环在某一范围”使用range()” >>> cells = ['cellA', 'cellB', 'cellC', 'cellD']
>>> for i in range(0,3): #实际中 0<=i<3
... print(cells[i])
...
cellA
cellB
cellC
range()函数可以指定步长 >>> cells = ['cellA', 'cellB', 'cellC', 'cellD','cellE','cellF','cellG']
>>> for i in range(0,7,2):
... print(cells[i])
...
cellA
cellC
cellE
cellG