python中的Dict字典/对象遍历迭代
student = {'li': 17, 'zc': 15, 'se': 19, 'ww': 20}
普通遍只有key
for item in student:
print(item)
# li zc se ww
值的遍历 val in Dict.values()
for item in student.values():
print(item)
#17 15 19 20
键值遍历 key,val in Dict.items()
for key,val in student.items():
print(key,val)
# li 17 zc 15 se 19 ww 20
判断一个对象是可迭代对象
from collections.abc import Iterable
print(isinstance(student, Iterable)) # True

浙公网安备 33010602011771号