DEV Community

Mr #1738
Mr #1738

Posted on

Augmented Assignment Operators in Python.

Augmented assignment operators have a special role to play in Python programming. It basically combines the functioning of the arithmetic or bitwise.
When assigning a value to a variable, you will frequently use the variable itself. For example, after assigning 42 to the variable spam, you would increase the value in spam by 1 with the following code:

>>> spam = 42
>>> spam = spam + 1
>>> spam
43
Enter fullscreen mode Exit fullscreen mode

As a shortcut, you can use the augmented assignment operator += to do the same thing:

>>> spam = 42
>>> spam += 1
>>> spam
43
Enter fullscreen mode Exit fullscreen mode

Top comments (0)