[python] 파이썬 dict.fromkeys() 딕셔너리 생성 메소드 정리

jaylnne·2022년 5월 6일
0

Python

목록 보기
1/6

dict.fromkeys(seq, value)

  • 딕셔너리를 생성할 때 편리하게 사용할 수 있는 메소드. seq 옵션 값에 문자열을 입력할 수도 있다.
  • seq: 생성하려는 dictionary의 키(key)의 목록
  • value: 생성하려는 dictionary의 값(value)

사용 예시

seq = ('name', 'age', 'sex')

dict_1 = dict.fromkeys(seq)
print(dict_1)

dict_2 = dict.fromkeys(seq, 10)
print(dict_2)

## result ##
{'age':None, 'name':None, 'sex':None}
{'age':10, 'name':10, 'sex':10}
profile
스스로 정한 목표에 도달하기 위해 달리는 걸 즐기는 사람 🏃‍♀️

0개의 댓글