python中ChainMap如何创建对象
小妮浅浅
2021-08-17 11:19:082724浏览 · 0收藏 · 0评论
说明
1、使用ChainMap类方法创建对象.fromkeys()。
2、使用可迭代键和所有键的可选默认值。若调用.fromkeys()上的ChainMap和迭代键作为参数,则得到的链条地图为字典。
键来自输入可迭代对象,默认值为None。或者,第二个参数可以传输。fromkeys()为每个键提供合理的默认值。
实例
>>> from collections import ChainMap >>> ChainMap.fromkeys(["one", "two","three"]) ChainMap({'one': None, 'two': None, 'three': None}) >>> ChainMap.fromkeys(["one", "two","three"], 0) ChainMap({'one': 0, 'two': 0, 'three': 0})
以上就是python中ChainMap创建对象的方法,希望对大家有所帮助。更多Python学习指路:python基础教程
关注公众号,随时随地在线学习
相关文章