一.循环结构
1.for循环
1.for循环
结构:”for x in y:”in后面是我们要遍历的list
其中y是我们要循环的结构List,x是其中的元素。
int_month = [1,2,3,4]
for i in int_month:
print(i)
2.第二种for循环
for i in range(n): range(n)就是从0到n-1
i从0到n-1
for i in range(5):
print(i)
3.while循环
while condition:
i = 0
while i<3:
print(i)
i+=1
4.List of List结构:对于list中的str类型,一定要加上引号
遍历两个List,先遍历外层List,再内层List
打印List of List结构中的每一个元素
names = [[1,2,3,4],[5,6,7]]
for i in names:
print(i)
for i in names:
for j in i:
print(j)