该方法用于创建并返回一个新的字典.两个参数,第一个为字典的键,第二个为字典的值(默认为None).

示例:
1.

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
>>> dict = dict.fromkeys([1,2,3])
>>> dict
{1: None, 2: None, 3: None}
>>> dict = dict.fromkeys([1,2,3],'test')
>>> dict
{1: 'test', 2: 'test', 3: 'test'}
  1. 这里需要注意!!!(没你想的那么好)
>>> dict = dict.fromkeys([1,2,3],['one','two','three'])
>>> dict
{1: ['one', 'two', 'three'], 2: ['one', 'two', 'three'], 3: ['one', 'two', 'three']}
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄