DEV Community

DDSRY
DDSRY

Posted on • Updated on

What is the Meaning of += in Python?

Meaning of += in Python Programming language?

  • Do you know how in English we can rewrite "it is" to be "it's"?

  • Or we can rewrite "you are" to "you're?

  • That's called contraction, and this is kind of like a
    contraction for the two operations = and +.

  • That means x = x+y is the same as x += y.

Top comments (1)

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Officially, this is known as a "compound operator", and there's one for each of the five basic math operators in Python:

x = 5

x += 2  # 7
x -= 1  # 6
x *= 5  # 30
x /= 2  # 15
x %= 2  # 1

P.S. You'll want to drop the #help tag from your post, as that's only for questions. #beginners might be a good fit, though.