Guidelines

잘λͺ»λœ 값을 λ‚˜νƒ€λ‚΄λŠ” ValueError

ValueError μ˜ˆμ™ΈλŠ” 잘λͺ»λœ 값이 μ‚¬μš©λ  λ•Œ λ°œμƒν•˜λŠ” μ˜ˆμ™Έμž…λ‹ˆλ‹€.


ValueError μ˜ˆμ™Έμ˜ λ°œμƒ 상황

  1. μˆ«μžκ°€ μ•„λ‹Œ 것을 숫자둜 λ³€ν™˜ν•˜λ € ν•  λ•Œ: λ¬Έμžμ—΄ 'hello'λ₯Ό int() 및 float() ν•¨μˆ˜λ₯Ό ν™œμš©ν•΄ 숫자둜 λ³€ν™˜ν•˜λ©΄ μ—λŸ¬κ°€ λ°œμƒν•©λ‹ˆλ‹€.

  2. μ†Œμˆ˜μ μ΄ μžˆλŠ” 숫자 ν˜•μ‹μ˜ λ¬Έμžμ—΄μ„ μ •μˆ˜λ‘œ λ³€ν™˜ν•˜λ € ν•  λ•Œ: '3.14'와 같은 μ‹€μˆ˜λ₯Ό ν‘œν˜„ν•œ λ¬Έμžμ—΄μ„ int()둜 λ³€ν™˜ν•˜λ©΄ μ—λŸ¬κ°€ λ°œμƒν•©λ‹ˆλ‹€.

ValueError μ˜ˆμ™Έ λ°œμƒ μ˜ˆμ‹œ
try: number = int("hello") except ValueError: print("μˆ«μžκ°€ μ•„λ‹Œ 값을 숫자둜 λ³€ν™˜ν•˜λ €κ³  ν–ˆμŠ΅λ‹ˆλ‹€.") try: number = int("3.14") except ValueError: print("μ†Œμˆ˜μ μ΄ μžˆλŠ” λ¬Έμžμ—΄μ„ int() ν•¨μˆ˜λ‘œ λ³€ν™˜ν•˜λ €κ³  ν–ˆμŠ΅λ‹ˆλ‹€.")
Mission
0 / 1

μˆ«μžκ°€ μ•„λ‹Œ 값을 숫자둜 λ³€ν™˜ν•˜λ € ν•  λ•Œ, ValueErrorκ°€ λ°œμƒν•  수 μžˆλ‹€.

O
X

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result