프로그래밍 언어/Python

[Python] 딕셔너리 키, 값 쌍 얻기 - items()

ShovelingLife 2024. 8. 26. 16:31
>>> car = {"name" : "BMW", "price" : "7000"} 
>>> car.items() 
dict_items([('name', 'BMW'), ('price', '7000')])

 

items 함수를 사용하면 딕셔너리의 값을 반복할 때 키와 값을 접근하기가 매우 유용해진다

>>> car = {"name" : "BMW", "price" : "7000"} 
>>> for key, val in car.items():
...		print("key : {} value : {}".format(key,val)) 

key : name value : BMW 
key : price value : 7000

 

출처