python中内置函数 dict() 函数,
作用是将传入的键值对或传入的可迭代的对象如列表元组之类的对象进行转换创建一个键值对对象返回.
dict() 函数的语法是:
class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
示例:
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}
dict(x=5, y=0) #输出 {'y': 0, 'x': 5}
dict([('x', 5), ('y', -5)]) #输出 {'y': -5, 'x': 5}
dict([('x', 5), ('y', -5)], z=8) #输出 {'z': 8, 'y': -5, 'x': 5}
dict(dict(zip(['x', 'y', 'z'], [1, 2, 3]))) #输出 {'z': 3, 'y': 2, 'x': 1}
dict({'x': 4, 'y': 5}) #输出 {'x': 4, 'y': 5}
dict({'x': 4, 'y': 5}, z=8) #输出 {'x': 4, 'z': 8, 'y': 5}