|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
dict1.fromkeys((1, 2, 3), ('one', 'two', 'three'))
也就是dic1={1: ('one', 'two', 'three'), 2: ('one', 'two', 'three'), 3: ('one', 'two', 'three')}
创建了dict1之后,我想看一下dict[1]会打印什么,但是会报错。
dict2 ={1:'ss', 2:'dd'}
dict2[1] = 'ss'
dict2却可以实现,但是dict1却不行,请问为啥。
把函数的用法搞清楚
- >>> dict1={}
- >>> dict1.fromkeys((1, 2, 3), ('one', 'two', 'three'))
- {1: ('one', 'two', 'three'), 2: ('one', 'two', 'three'), 3: ('one', 'two', 'three')}
- >>> dict1
- {}
- >>> dict1 = dict1.fromkeys((1, 2, 3), ('one', 'two', 'three'))
- >>> dict1
- {1: ('one', 'two', 'three'), 2: ('one', 'two', 'three'), 3: ('one', 'two', 'three')}
复制代码
返回值
该方法 返回一个新字典。
|
|