循环包括while循环和for循环
while循环指当满足某个条件的时候会一直循环
for循环给定了一个变量的区间(迭代器)
P5 while循环
condition = 1
while condition < 10:
print(condition)
condition = condition + 1
while True:
False
while True:
print("I'm True")
会一直循环打印I‘m True
ctrl+c终止运行
P6 for循环
example_list = [1, 2, 3, 4, 5, 6, 7, 12, 543, 876, 12, 3, 2, 5]
for i in example_list:
print(i)
print('inner of for')
print('outer of for')
for循环和while循环的第一条语句以冒号结尾
特别注意空格(全选需要改变结构的内容,ctrl+方括号可批量改变空格结构,“ [ ”向左,
“ ]”向右)
for i in range(1, 10):
print(i)
range(start,stop[,step]) 从start开始,到stop的前一位结束,step为步长,默认为1