Python Tutorials · Python Operators
Assignment Operators
Learn all about Assignment Operators in this comprehensive tutorial.
5 min read beginner
- •Assignment operators are used to assign values to variables:
- •Python 3.
Assignment Operators
Assignment operators are used to assign values to variables:
| Operator | Example | Same As | Try it |
|---|---|---|---|
| = | x = 5 | x = 5 | Try it » |
| += | x += 3 | x = x + 3 | Try it » |
| -= | x -= 3 | x = x - 3 | Try it » |
| *= | x *= 3 | x = x * 3 | Try it » |
| /= | x /= 3 | x = x / 3 | Try it » |
| %= | x %= 3 | x = x % 3 | Try it » |
| //= | x //= 3 | x = x // 3 | Try it » |
| **= | x **= 3 | x = x ** 3 | Try it » |
| &= | x &= 3 | x = x & 3 | Try it » |
| |= | x |= 3 | x = x | 3 | Try it » |
| ^= | x ^= 3 | x = x ^ 3 | Try it » |
| >>= | x >>= 3 | x = x >> 3 | Try it » |
| <<= | x <<= 3 | x = x << 3 | Try it » |
| := | print(x := 3) | x = 3print(x) | Try it » |
The Walrus Operator
Python 3.8 introduced the := operator, known as the "walrus operator". It assigns values to variables as part of a larger expression:
python
Module quiz
2 questions1
Which of the following is true about Assignment Operators?
2
What is the most common pitfall when working with Assignment Operators?
Answer all questions to submit.