반응형
Python 8번째 영상의 내용은 Dictionaries 사용법이다.
Key 와 value 를 pair로 관리하는 방식이다.
Dictionaries 생성은 {}를 사용하는 것이다.
d = {} 로 지정한 후
d["George"] = 24
d["Tom"] = 32
d["Jenny"] = 16
으로 Key와 value를 지정하여 사용할 수 있다.
d 안에 없는 Key를 사용하게 되면 에러메세지가 나온다.
d 에 있는 Key와 value를 확인하는 코드를 사용할 수 있는데 이는 다음과 같다.
# how to iterate over key-value pairs?
for key, value in d.items():
print("key:")
print(key)
print("value:")
print(value)
print("")
해당 for 구문을 사용하면 key와 value 값을 출력해준다.
반응형
'Information > IT' 카테고리의 다른 글
[How to] 챗GPT 잘 사용하는 방법 (0) | 2024.01.24 |
---|---|
[Mac] 맥 사파리 시스템 글꼴 설정 방법 (0) | 2023.04.25 |
[Review]Python Tutorial #7. More About For Loops in Python & Solutions to the Last 2 Problems (0) | 2019.01.27 |
[Review]Python Tutorial #6. While loops and the break statement in Python (0) | 2019.01.23 |
[Review] Python Tutorial #5. Introduction to For Loops (0) | 2019.01.02 |