Guidelines

νŠœν”Œμ˜ λΆˆλ³€μ„±κ³Ό μ˜ˆμ™Έ 처리

νŒŒμ΄μ¬μ—μ„œ νŠœν”Œμ€ ν•œ 번 μƒμ„±λ˜λ©΄ κ·Έ λ‚΄μš©μ„ λ³€κ²½ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

νŠœν”Œμ˜ λΆˆλ³€μ„±μ„ μœ„λ°˜ν•˜λ©΄ TypeError μ˜ˆμ™Έκ°€ λ°œμƒν•©λ‹ˆλ‹€.

μ˜ˆμƒμΉ˜ λͺ»ν•œ λ™μž‘μœΌλ‘œ νŠœν”Œμ˜ λΆˆλ³€μ„±μ„ μœ„λ°˜ν•΄ ν”„λ‘œκ·Έλž¨μ— 였λ₯˜κ°€ λ°œμƒν•˜λŠ” 것을 λ°©μ§€ν•˜λ €λ©΄ try/except 문을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

try/except 문은 try λΈ”λ‘μ—μ„œ μ˜ˆμ™Έκ°€ λ°œμƒν•˜λ©΄ except λΈ”λ‘μ˜ μ½”λ“œλ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€.

νŠœν”Œ λΆˆλ³€μ„± μ˜ˆμ™Έ 처리
my_tuple = (1, 2, 3) try: # 2번째 μš”μ†Œ λ³€κ²½ μ‹œλ„ my_tuple[1] = 5 except TypeError as e: # TypeError μ˜ˆμ™Έ 처리 print(f"였λ₯˜ λ°œμƒ: {e}")

이 μ½”λ“œμ—μ„œ νŠœν”Œμ˜ 2번째 μš”μ†Œλ₯Ό λ³€κ²½ν•˜λŠ” my_tuple[1] = 5λŠ” TypeErrorλ₯Ό λ°œμƒμ‹œν‚΅λ‹ˆλ‹€.

μ½”λ“œ μ˜ˆμ œμ™€ 같이 except λΈ”λ‘μ—μ„œ TypeError μ˜ˆμ™Έλ₯Ό μ²˜λ¦¬ν•˜κ³  였λ₯˜ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Mission
0 / 1

νŠœν”Œμ˜ μš”μ†Œλ₯Ό λ³€κ²½ν•˜λ €κ³  μ‹œλ„ν•˜λ©΄ TypeErrorκ°€ λ°œμƒν•œλ‹€.

O
X

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result