파이썬답게 딕셔너리 사용하기

Python의 데이터 타입

Jason Myers

Instructor

파이썬답게 딕셔너리 다루기

  • .items() 메서드는 반복 가능한 객체를 반환합니다
for gallery, phone_num in art_galleries.items():
    print(gallery)
    print(phone_num)
'Miakey Art Gallery'
'(718) 686-0788'
'Morning Star Gallery Ltd'
'(212) 334-9330'}
'New York Art Expo Inc'
'(212) 363-8280'
Python의 데이터 타입

딕셔너리에서 데이터 확인하기

  • .get()은 키 확인을 위해 많은 작업을 수행합니다
  • in 연산자가 훨씬 효율적이고 명확합니다
'11234' in art_galleries
False
if '10010' in art_galleries:
    print('I found: %s' % art_galleries['10010'])
else:
    print('No galleries found.')
I found: {'Nyabinghi Africian Gift Shop': '(212) 566-3336'}
Python의 데이터 타입

연습해 봅시다!

Python의 데이터 타입

Preparing Video For Download...