Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

미니는 밍기적

[Python] dictionary 자료구조 - key&value 본문

Python/PythonProgramming

[Python] dictionary 자료구조 - key&value

sefdcrxe 2022. 10. 22. 17:04

*비어있는 딕셔너리를 생성하려면 -> {} 를 사용 + Key:Value 를 쌍으로 입력 + 구분은 콤마 ","

* Key 값은 단 1개만 존재함

 

key value
이름 mini
나이 21

 

*key에 맞는 Value를 알기 위해서는 ['Key'] 을 입력

 

*key 값을 얻어오기 위해서는 keys() 를 사용하며,Value 값을 얻어오기 위해서는 values() 를 사용

*key,value 모두 얻어오기 위해서는 items() 를 사용

 

a = str(input()) #문자열로 받쨔.

print(dic[a])

 

 

--------------------------

homework 2-2 자판기

for keys in dict_drink:

   print(keys, ':', dict_drink[keys][1], "won ," , dict_drink[keys][0], "left .")

-------------------

homework 2-3 자판기

 

 

 

 

----> value값이 list일 때는 keys 값에 index 사용하여 순서 지정하는 경우가 더러 있다.

value는 keys의 쌍이라 keys를 불러와야하는데.  계속 value값에만 집착한 나는 몽총이. 

 

 

*print(a, end = ' ')

end = ' ' 는 줄바꿈이 아닌 공백 하나를 두고 가로로 배열