Assignment Operators in Python
October 26, 2020
In all programming languages you will find assignment operators. Assignment operators are used to assign values to variables. In this tutorial I will show you the assignment operators available in Python.
Now, let’s see the assignment operators in Python:
| Operator | Example | Equivalent |
|---|---|---|
| = | x = 5 | x = 5 |
| += | x += 5 | x = x + 5 |
| -= | x -= 5 | x = x – 5 |
| *= | x *= 5 | x = x * 5 |
| /= | x /= 5 | x = x / 5 |
| %= | x %= 5 | x = x % 5 |
| //= | x //= 5 | x = x // 5 |
| **= | x **= 5 | x = x ** 5 |
| &= | x &= 15 | x = x & 15 |
| |= | x |= 15 | x = x | 15 |
| ^= | x ^= 15 | x = x ^ 15 |
| >>= | x >>= 1 | x = x >> 1 |
| <<= | x <<= 1 | x = x << 1 |
Python Code with assignment & arithmetic operators:
x=5 y=6 z=x+y print(z)
Output:
11
In this tutorial, I have shown assignment operators in Python. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.