用for
循环遍历llist
or tuple
or dict
称之为迭代
1. 迭代dict,默认是迭代key
people = {'name':'zhoubo', 'age': 23, 'city': 'Guangzhou'}
for key in people:
print(key)
#output
name
age
city
2. 迭代value
for value in people.values():
print(value)
#output
zhuobo
23
Guangzhou
3. 同时迭代key
and value
for k, v in people.items():
print(k + ' : ' + v)
#output
name : zhuobo
age : 23
city : Guangzhou