后浪云Python教程:python中ChainMap如何创建对象
说明
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教程
版权声明:
作者:后浪云
链接:https://www.idc.net/help/176353/
文章版权归作者所有,未经允许请勿转载。
THE END