dict(创建)

1、>>>dict() # 创建空字典

{}

2、>>>{'a': 'a', 'b': 'b', 'c', 'c'}

3、>>> dict(a='a'b='b't='t') # 传入关键字

{'a''a''b''b''t''t'}

4、>>> dict(zip(['one''two''three'][123])) # 映射函数方式来构造字典

{'three'3'two'2'one'1}

5、>>> dict([('one'1)('two'2)('three'3)]) # 可迭代对象方式来构造字典

{'three'3'two'2'one'1}

posted @ 2020-08-05 08:18  6+0  阅读(182)  评论(0编辑  收藏  举报