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

posted @ 2026-04-20 11:14  幻影之舞  阅读(4)  评论(0)    收藏  举报