python fromkeys 方法

fromkeys(seq,b) 方法用于创建一个新字典,以 seq 中元素作为key值,b作为字典中键对应的value

seq = ('Google', 'Runoob', 'Taobao')
this=dict.fromkeys(seq)
this
{'Google': None, 'Runoob': None, 'Taobao': None}
this=dict.fromkeys(seq,10)
this
{'Google': 10, 'Runoob': 10, 'Taobao': 10}

 

posted @ 2022-02-11 16:44  keep2021  阅读(48)  评论(0编辑  收藏  举报