Python遍历字典的几种方式
“ 记录遍历字典的几种方式”
#遍历字典key值---方法1
for key in dict1:
print(key)
# 遍历字典key值---方法2
for key in dict1.keys():
print(key)
#遍历字典value值
for value in dict1.values():
print(value)
#遍历字典中的元素
for item in dict1.items():
print(item)输出结果:
#遍历字典key值---方法1 name age native opus #遍历字典key值---方法2 name age native opus #遍历字典value值 吴亦凡 29 广州 大碗宽面 #遍历字典中的元素 (‘name‘, ‘吴亦凡‘) (‘age‘, ‘29‘) (‘native‘, ‘广州‘) (‘opus‘, ‘大碗宽面‘)
相关推荐
非攻 2020-10-25
youandme 2020-05-11
haokele 2020-04-23
paopao00 2020-04-07
zhangpan 2020-02-23
wyqwilliam 2020-02-14
Winterto0 2020-01-13
JackLang 2019-12-28
LczPtr 2019-12-24
georgeandgeorge 2019-12-09
wordmhg 2019-11-01
小炮集揣 2019-05-03
ciqingloveless 2019-06-30
yuan00yu 2019-06-28
Kwong 2019-06-27
远哥的小迷弟 2019-03-08
一叶不知秋 2018-01-23