#1.遍历字典的key for key in dict1.keys(): print(key) # name age weight height #2.遍历字典的value for value in dict1.values(): print(value) #jch1 22 71.2 170 #3.遍历字典的元素 for item in dict1.items(): print(item) #('name', 'jch1') ('age', 22) ('weight', 71.2) ('height', 170) #4.遍历字典的键值对 for key, value in dict1.items(): print(f'{key} = {value}') #name = jch1 age = 22 weight = 71.2 height = 170
015-Python入门(遍历字典)
最新推荐文章于 2024-08-19 13:32:52 发布