dict()

dict() 用法如下:

>>>dict()    # 创建空字典
{}
>>> dict(a='a', b='b', t='t') # 通过传入关键字来构造字典 {'a': 'a', 'b': 'b', 't': 't'}
>>> dict(zip(['one', 'two', 'three'], [1, 2, 3])) # 通过映射函数方式来构造字典 {'three': 3, 'two': 2, 'one': 1}
>>> dict([('one', 1), ('two', 2), ('three', 3)]) # 通过可迭代对象方式来构造字典 {'three': 3, 'two': 2, 'one': 1}

    

原文地址:https://www.cnblogs.com/pzk7788/p/10259050.html