Guidelines

+=, -= λŠ” 무엇을 μ˜λ―Έν• κΉŒ?

+=, -= λ“±κ³Ό 같이 μ—°μ‚°μžμ™€ = κΈ°ν˜Έκ°€ ν•¨κ»˜ μ‚¬μš©λ˜λŠ” μ—°μ‚°μžλ₯Ό 볡합 λŒ€μž… μ—°μ‚°μž(Compound Assignment Operators)라고 ν•©λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄ x += yλŠ” x와 yλ₯Ό λ”ν•œ 값을 x에 ν• λ‹Ήν•˜λŠ” x = x + y와 같은 μ˜λ―Έμž…λ‹ˆλ‹€.

볡합 λŒ€μž… μ—°μ‚°μž μ˜ˆμ‹œ
x = 10 y = 5 x += y # x = x + y print(x) # 15

볡합 λŒ€μž… μ—°μ‚°μžμ˜ μ’…λ₯˜

파이썬 볡합 λŒ€μž… μ—°μ‚°μžλŠ” +=(λ§μ…ˆ), -=(λΊ„μ…ˆ), *=(κ³±μ…ˆ), /=(λ‚˜λˆ—μ…ˆ), %=(λ‚˜λ¨Έμ§€) 등이 μžˆμŠ΅λ‹ˆλ‹€.

볡합 λŒ€μž… μ—°μ‚°μž μ˜ˆμ‹œ
number = 10 print("number:", number) # 10 number += 5 # number = number + 5 print("number += 5:", number) # 15 number -= 3 # number = number - 3 print("number -= 3:", number) # 12 number *= 2 # number = number * 2 print("number *= 2:", number) # 24 number /= 4 # number = number / 4 print("number /= 4:", number) # 6.0 number %= 2 # number = number % 2 print("number %= 2:", number) # 0.0

볡합 λŒ€μž… μ—°μ‚°μžλŠ” μ•„λž˜μ™€ 같이 1λΆ€ν„° 5κΉŒμ§€ 숫자λ₯Ό λ”ν•˜λŠ” λ°˜λ³΅λ¬Έμ—μ„œλ„ 자주 ν™œμš©λ©λ‹ˆλ‹€.

μ°Έκ³  : λ°˜λ³΅λ¬Έμ— λŒ€ν•œ μžμ„Έν•œ λ‚΄μš©μ€ νŒŒμ΄μ¬μ—μ„œ 쑰건에 따라 λ°˜λ³΅μ„ μˆ˜ν–‰ν•˜λŠ” 방법 μˆ˜μ—…μ—μ„œ μžμ„Ένžˆ μ†Œκ°œν•˜κ² μŠ΅λ‹ˆλ‹€.

볡합 λŒ€μž… μ—°μ‚°μž μ˜ˆμ‹œ
numbers = [1, 2, 3, 4, 5] total = 0 for number in numbers: total += number print("total:", total) # 15
Mission
0 / 1

λ‹€μŒ 쀑 x -= y의 μ˜λ―ΈλŠ” λ¬΄μ—‡μΌκΉŒμš”?

`x -= y`λŠ” `x = `와 κ°™μŠ΅λ‹ˆλ‹€.
x + y
x - y
x * y
x / y

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result