Guidelines

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

KeyErrorλŠ” λ”•μ…”λ„ˆλ¦¬μ— μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν‚€λ‘œ μ ‘κ·Όν•˜λ €κ³  μ‹œλ„ν•  λ•Œ λ°œμƒν•˜λŠ” μ˜ˆμ™Έμž…λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄:

KeyError λ°œμƒ μ˜ˆμ‹œ
person = { "이름": "μ½”λ“œν”„λ Œμ¦ˆ", "직업": "개발자", } # μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” 킀인 "λ‚˜μ΄"에 μ ‘κ·Ό, KeyError λ°œμƒ age = person["λ‚˜μ΄"] # KeyError: 'λ‚˜μ΄'

KeyError λ°©μ§€ν•˜κΈ°

KeyErrorλ₯Ό λ°©μ§€ν•˜λ €λ©΄ λ”•μ…”λ„ˆλ¦¬μ—μ„œ μ ‘κ·Όν•˜κΈ° 전에 ν•΄λ‹Ή ν‚€κ°€ μ‘΄μž¬ν•˜λŠ”μ§€ 확인해야 ν•©λ‹ˆλ‹€. 이λ₯Ό μœ„ν•΄ in μ—°μ‚°μžλ₯Ό μ‚¬μš©ν•˜κ±°λ‚˜ get() λ©”μ„œλ“œλ₯Ό ν™œμš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

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

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result