美文网首页python百例
50-字典基础用法

50-字典基础用法

作者: 凯茜的老爸 | 来源:发表于2018-07-31 17:11 被阅读8次
adict = dict()  # {}
dict(['ab', 'cd'])
bdict = dict([('name', 'bob'),('age', 25)])
{}.fromkeys(['zhangsan', 'lisi', 'wangwu'], 11)

for key in bdict:
    print('%s: %s' % (key, bdict[key]))

print("%(name)s: %(age)s" % bdict)

bdict['name'] = 'tom'
bdict['email'] = 'tom@tedu.cn'

del bdict['email']
bdict.pop('age')
bdict.clear()

相关文章

网友评论

    本文标题:50-字典基础用法

    本文链接:https://www.haomeiwen.com/subject/avbhvftx.html