1、遍历key
>>> d
{'set': {'c', 'a', 'b'}, 'list': [1, 2, 3], 'tuple': (4, 5, 6), 'version': 'python3.7.4'}
>>> for k in d.keys():
... print(k)
...
set
list
tuple
version
2、遍历value
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for value in d.values():
print (value)
[1, 2, 3]
123
python3
(4, 5, 6)
3、遍历字典项
>>> for kv in a.items():
print(kv)
('a', '1')
('b', '2')
('c', '3')
4、遍历key-value
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for (key,value) in d.items():
print(key,value)
list [1, 2, 3]
1 123
111 python3
tuple (4, 5, 6)
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果用户发布的作品侵犯了您的权利,请联系管理员:wupeng@hqwx.com
环球青藤
官方QQ群扫描上方二维码或点击一键加群,免费领取大礼包,加群暗号:青藤。 一键加群