python3基础4-字典

#coding:utf-8
#允许汉语注释
#添加字典元素
a= {'color': 'green', 'points': 5}
print(a)
a['x']=1
a['y']=2
a['z']=1
print(a)
#删除键—值对
del a['points']
print(a)
#遍历所有的键—值对
for key,value in a.items():
    print(key,value)

for key1,value1 in a.items():
    print(key1,value1)

for key3 in a.keys():
    print(key3)

for v3 in a.values():
    print(str(v3))
print("\n\n")

#删除重复值
print('del multi\n')
for v3 in set(a.values()):
    print(v3)

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>