Assignment Operators
Files associated with this lesson:
Assignment Operators.ipynb
Assignment Operators¶
Used to perform an operation and change a value in place. For example, increment a variable by one.
x = 5
x = x + 1
# is the same as:
x += 1
There's an assignment operator for each arithmetic operator:
In [2]:
x = 3
x += 1
print(x)
In [3]:
x = 3
x -= 1
print(x)
In [5]:
x = 3
x *= 2
print(x)
In [6]:
x = 3
x /= 2
print(x)
In [7]:
x = 3
x //= 2
print(x)
In [8]:
x = 3
x **= 2
print(x)
In [9]:
x = 3
x %= 2
print(x)
In [ ]: