Guidelines

format() ν•¨μˆ˜ μœ μ˜μ‚¬ν•­ - indexError

format() ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•  λ•Œ, λ¬Έμžμ—΄ λ‚΄μ˜ μ€‘κ΄„ν˜Έ {}의 κ°œμˆ˜μ™€ format() ν•¨μˆ˜μ— μ „λ‹¬λœ λ§€κ°œλ³€μˆ˜μ˜ μˆ˜κ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμœΌλ©΄ indexError μ˜ˆμ™Έκ°€ λ°œμƒν•©λ‹ˆλ‹€.

indexErrorλŠ” format() ν•¨μˆ˜μ— μ „λ‹¬λœ λ§€κ°œλ³€μˆ˜λ³΄λ‹€ λ§Žμ€ μ€‘κ΄„ν˜Έκ°€ λ¬Έμžμ—΄ 내에 μžˆμ–΄, μ€‘κ΄„ν˜Έμ— 맀핑할 값을 찾지 λͺ»ν•  λ•Œ λ°œμƒν•©λ‹ˆλ‹€.


indexError μ˜ˆμ‹œ
greeting = "μ•ˆλ…•ν•˜μ„Έμš”, {0}λ‹˜! μ˜€λŠ˜μ€ {1} μž…λ‹ˆλ‹€. {2}" try: formatted_greeting = greeting.format("μ½”λ“œν”„λ Œμ¦ˆ", "ν™”μš”μΌ") print(formatted_greeting) except IndexError as e: print(f"였λ₯˜ λ°œμƒ: {e}")

indexError ν•΄κ²° 방법

indexErrorλ₯Ό λ°©μ§€ν•˜κΈ° μœ„ν•΄ λ¬Έμžμ—΄ λ‚΄μ˜ μ€‘κ΄„ν˜Έ κ°œμˆ˜μ™€ format() ν•¨μˆ˜μ— μ „λ‹¬λ˜λŠ” λ§€κ°œλ³€μˆ˜μ˜ 수λ₯Ό μΌμΉ˜μ‹œμΌœμ•Ό ν•©λ‹ˆλ‹€.

indexError ν•΄κ²°
# {2}λ₯Ό μ œκ±°ν•˜μ—¬ indexError ν•΄κ²° greeting = "μ•ˆλ…•ν•˜μ„Έμš”, {0}λ‹˜! μ˜€λŠ˜μ€ {1} μž…λ‹ˆλ‹€." formatted_greeting = greeting.format("μ½”λ“œν”„λ Œμ¦ˆ", "ν™”μš”μΌ") print(formatted_greeting) # "μ•ˆλ…•ν•˜μ„Έμš”, κΉ€μ² μˆ˜λ‹˜! μ˜€λŠ˜μ€ ν™”μš”μΌ μž…λ‹ˆλ‹€."
Mission
0 / 1

format() ν•¨μˆ˜μ—μ„œ λ¬Έμžμ—΄ λ‚΄μ˜ μ€‘κ΄„ν˜Έμ˜ κ°œμˆ˜μ™€ format() ν•¨μˆ˜μ— μ „λ‹¬λ˜λŠ” λ§€κ°œλ³€μˆ˜μ˜ μˆ˜κ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμœΌλ©΄ indexError μ˜ˆμ™Έκ°€ λ°œμƒν•œλ‹€.

O
X

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result