π 1. λμ
λ리 (dictionary)
πΉ κ°λ
- ν€(key)μ κ°(value)μ μμΌλ‘ λ°μ΄ν°λ₯Ό μ μ₯νλ μλ£ν
- μμκ° μλ(3.6 μ΄μ ), λ³κ²½ κ°λ₯ν(mutable), ν΄μ κΈ°λ°μ ꡬ쑰
- ν€λ μ€λ³΅λ μ μκ³ , λ³κ²½ λΆκ°λ₯ν(immutable) νμ
μ΄μ΄μΌ ν¨ (λ¬Έμμ΄, μ μ, νν λ±)
πΉ μμ
student = {
"name": "Alice",
"age": 21,
"major": "Computer Science"
}
"name"μ ν€μ΄κ³ "Alice"λ κ°μ΄λ€
- μ 체μ μΌλ‘
key: value νν
πΉ μ£Όμ νΉμ§
| νΉμ§ |
μ€λͺ
|
| ν€λ₯Ό μ΄μ©ν λΉ λ₯Έ μ κ·Ό |
student["age"] β 21 |
| κ° λ³κ²½ κ°λ₯ |
student["age"] = 22 |
| μλ‘μ΄ ν€ μΆκ° |
student["grade"] = "A" |
| ν€ μμ |
del student["major"] |
| μ 체 μν |
for key, value in student.items(): |
πΉ λ©μλ
| λ©μλ |
μ€λͺ
|
dict.keys() |
λͺ¨λ ν€ λ°ν |
dict.values() |
λͺ¨λ κ° λ°ν |
dict.items() |
(ν€, κ°) μ λ°ν |
dict.get(key, default) |
ν€κ° μμΌλ©΄ default λ°ν |
π 2. νν (tuple)
πΉ κ°λ
- μ¬λ¬ κ°μ νλμ λ¬ΆμμΌλ‘ μ μ₯νλ μλ£ν