定义和用法
fromkeys() 方法返回具有指定键和值的字典。
实例
例子 1
创建拥有 3 个键的字典,值均为 0:
x = ('key1', 'key2', 'key3') y = 0 thisdict = dict.fromkeys(x, y) print(thisdict)
运行实例 »
例子 2
与上例相同,但未指定值:
x = ('key1', 'key2', 'key3') thisdict = dict.fromkeys(x) print(thisdict)
语法
dict.fromkeys(keys, value)
参数
返回:Python 字典