50-字典基础用法

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'] = '[email protected]' del bdict['email'] bdict.pop('age') bdict.clear()

结果输出:
 

猜你喜欢

转载自www.cnblogs.com/hejianping/p/10907207.html
今日推荐