1.for … in 循环
循环,遍历,迭代 都是指把容器中的数据一个一个获取出来
lst = [1,2,3,4,5]
i = 0
while i<len(lst):
print(lst[i])
i...应用而生
语法:
for 变量 in 可迭代对象:
code ......遍历集合
container = {
"taibai","wusir","wuchao","bijiao"}
for i in container:
print(i)
3.遍历列表
''' Python...in container:
print(i)
6.遍历字典
container = {
1:"a",2:"b",3:"c"}
for i in container:
print(i)
7.变量的解包...[个数要匹配]
a,b = 1,2
a,b = (1,2)
a,b = [1,2]
#a,b = "567" #字符串有局限性,个数是2个,只能用2个变量收;
#a,b = {"a","b"} 集合有局限性