[python] 딕셔너리.items()

Robin·2022년 9월 21일

Python

목록 보기
9/11

.items()

딕셔너리.items()는 해당 딕셔너리의 키와 값을 튜플 형식으로 저장해준다.

>>> users = {'gunwoo':'gw', 'harry':'hyhl'}
>>> for user, id in users.items():
        print(user, id)
'gunwoo' 'gw'
'harry' 'hyhl'

위의 예시에서,
users.items()는 [("gunwoo", "gw"), ("harry", "hyhl")]의 값을 갖게 된다.

profile
Always testing, sometimes dog walking

0개의 댓글