파이썬 사전 fromkeys() 메서드
예시
모두 값이 0인 3개의 키가 있는 사전을 만듭니다.
x = ('key1', 'key2', 'key3')
y = 0
thisdict = dict.fromkeys(x, y)
print(thisdict)
정의 및 사용
이 fromkeys()
메서드는 지정된 키와 지정된 값이 있는 사전을 반환합니다.
통사론
dict.fromkeys(keys, value)
매개변수 값
Parameter | Description |
---|---|
keys | Required. An iterable specifying the keys of the new dictionary |
value | Optional. The value for all keys. Default value is None |
더 많은 예
예시
값을 지정하지 않고 위와 같은 예:
x = ('key1', 'key2', 'key3')
thisdict = dict.fromkeys(x)
print(thisdict)