成都创新互联网站制作重庆分公司

创新互联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教程


网站题目:创新互联Python教程:python中ChainMap如何创建对象
网站路径:http://www.cxhlcq.com/article/codpcig.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部