+=
, -=
λ 무μμ μλ―Έν κΉ?
+=
, -=
λ±κ³Ό κ°μ΄ μ°μ°μμ =
κΈ°νΈκ° ν¨κ» μ¬μ©λλ μ°μ°μλ₯Ό λ³΅ν© λμ
μ°μ°μ(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