'''
1、for 循环主要用于循环取值,例如列表、字典、字符串
2、for循环的次数取决于值的个数
while循环的次数取决于什么时候条件变为False
'''
一、为什么要用For循环
l = [111, 222, 333, 444, 555]
i =0
# while 可以做到,但是在有索引的情况下
while i
print(l[i])
i +=1
# for循环就很容易做到
for iin l:
print(i)
l2 = [['a', 1], ['b', 2], ['c', 3]]
# x, y 在l 中取值不是for的特性,实际上是解压赋值的特性
for x, yin l2:
print(x, y)
# 二、for + break/continue/else
for x in l:
print(x)
if x ==333:
break