Python의 데이터 타입
Jason Myers
Instructor
dict() 또는 {}로 생성art_galleries = {}
for name, zip_code in galleries:
art_galleries[name] = zip_code
for name in sorted(art_galleries)[-5:]:
print(name)
Zwirner David Gallery
Zwirner & Wirth
Zito Studio Gallery
Zetterquist Galleries
Zarre Andre Gallery
art_galleries['Louvre']
|--------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-1-4f51c265f287> in <module>()
--> 1 art_galleries['Louvre']
KeyError: 'Louvre'
.get() 메서드를 사용하면 오류 처리 없이 키에 안전하게 접근할 수 있습니다None을 반환하거나, 반환할 값을 직접 지정할 수 있습니다art_galleries.get('Louvre', 'Not Found')
'Not Found'
art_galleries.get('Zarre Andre Gallery')
'10011'
Python의 데이터 타입