6.0分支、循环、条件与枚举
while循环写法
while codition:
passwhile codition:
pass
else:
passfor循环遍历
主要是用来遍历/循环 序列或者集合、字典
for target_list in expression_list:
passa=['apple','orange','banana','grape']
for x in a:
print(x)a=[['apple','orange','banana','grape'],(1,2,3)]
for x in a:
for y in x:
print(y)注意:只有当for循环遍历正常结束时,才会执行else后的语句。若使用break中断循环,else后的语句将不被执行
for循环计数
循环中断
Last updated
Was this helpful?