Guidelines

λ”•μ…”λ„ˆλ¦¬ KeyError μ˜ˆμ™Έ μ²˜λ¦¬ν•˜κΈ°

KeyErrorλŠ” λ”•μ…”λ„ˆλ¦¬μ— μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” 킀에 μ ‘κ·Όν•˜λ €κ³  ν•  λ•Œ λ°œμƒν•˜λŠ” μ˜ˆμ™Έμž…λ‹ˆλ‹€.

μ•„λž˜ μ½”λ“œλŠ” λ”•μ…”λ„ˆλ¦¬μ— μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” price 킀에 μ ‘κ·Όν•˜μ—¬ KeyErrorκ°€ λ°œμƒν•˜λŠ” μ˜ˆμ‹œμž…λ‹ˆλ‹€.

KeyError λ°œμƒ μ˜ˆμ‹œ
user_info = { "username": "user123", "email": "user123@example.com", "location": "Seoul" } # "age" ν‚€κ°€ μ‘΄μž¬ν•˜μ§€ μ•Šμ•„ KeyError λ°œμƒ user_age = user_info["age"]

KeyErrorλ₯Ό μ˜ˆλ°©ν•˜λ €λ©΄ λ”•μ…”λ„ˆλ¦¬μ— μ ‘κ·Όν•˜κΈ° 전에 ν‚€κ°€ μ‘΄μž¬ν•˜λŠ”μ§€ 확인해야 ν•©λ‹ˆλ‹€.

이λ₯Ό μœ„ν•΄ in μ—°μ‚°μžλ₯Ό μ‚¬μš©ν•˜κ±°λ‚˜ get() λ©”μ„œλ“œλ₯Ό ν™œμš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒ μˆ˜μ—…μ—μ„œλŠ” in μ—°μ‚°μžμ™€ get() λ©”μ„œλ“œμ— λŒ€ν•΄ 쑰금 더 μžμ„Ένžˆ μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€.

Mission
0 / 1

λ”•μ…”λ„ˆλ¦¬μ— μ ‘κ·Όν•˜κΈ° 전에 ν•΄λ‹Ή ν‚€κ°€ μ‘΄μž¬ν•˜λŠ”μ§€ ν™•μΈν•˜λŠ” λ°©λ²•μœΌλ‘œ in ν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•  수 μžˆλ‹€.

O
X

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result