fromkeys疑惑
>>> dict1={}>>> dict1.fromkeys((1, 2, 3), ('one', 'two', 'three'))
{1: ('one', 'two', 'three'), 2: ('one', 'two', 'three'), 3: ('one', 'two', 'three')}
>>> print(dict1)
{}
小甲鱼说fromkeys方法是创建一个新字典,那么新字典的名字是什么?我们怎么调用这个新字典? dict1={}
a = dict1.fromkeys((1, 2, 3), ('one', 'two', 'three'))
print(a)
你想要的是这样的效果么。。。 Charles未晞 发表于 2018-5-3 15:50
你想要的是这样的效果么。。。
就是调用fromkeys方法时必须要指定新字典的名字,不指定就找不到是吧 shen1991 发表于 2018-5-3 15:55
就是调用fromkeys方法时必须要指定新字典的名字,不指定就找不到是吧
是的,不是 in-place操作。不会改变dict1。 Charles未晞 发表于 2018-5-3 15:59
是的,不是 in-place操作。不会改变dict1。
谢谢 请问这个函数的作用是什么?
页:
[1]