fromkeys() 메서드는 지정된 키와 지정된 값을 가진 사전을 반환합니다.
매개변수 | 필수 | 설명 |
---|---|---|
keys | 필수 | 새 사전의 키를 지정하는 iterator(반복자) |
value | 선택 | 모든 키의 값입니다. 기본값은 None입니다. |
x = ('key1', 'key2', 'key3') y = 0 thisdict = dict.fromkeys(x, y) print(thisdict)
결과
['key1': 0, 'key2': 0, 'key3': 0]
x = ('key1', 'key2', 'key3') thisdict = dict.fromkeys(x) print(thisdict)
결과
['key1': None, 'key2': None, 'key3': None]
© 2022 pinfo. All rights reserved.