Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Python Assignment Operators?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ = [1, 2, 3, 4, 5]3Order
Put the learning moves in the order that makes the concept easiest to apply.
Assignment operators are used to assign values to variables:
The Walrus Operator
Assignment Operators
Assignment Operators
Assignment operators are used to assign values to variables:
| Operator | Example | Same As | ||
|---|---|---|---|---|
| = | x = 5 | x = 5 | ||
| += | x += 3 | x = x + 3 | ||
| -= | x -= 3 | x = x - 3 | ||
| *= | x *= 3 | x = x * 3 | ||
| /= | x /= 3 | x = x / 3 | ||
| %= | x %= 3 | x = x % 3 | ||
| //= | x //= 3 | x = x // 3 | ||
| **= | x **= 3 | x = x ** 3 | ||
| &= | x &= 3 | x = x & 3 | ||
| = | x | = 3 | x = x | 3 |
| ^= | x ^= 3 | x = x ^ 3 | ||
| >>= | x >>= 3 | x = x >> 3 | ||
| <<= | x <<= 3 | x = x << 3 | ||
| := | print(x := 3) | x = 3 print(x) |
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:
Example
numbers = [1, 2, 3, 4, 5]
if (count := len(numbers)) > 3:
print(f"List has {count} elements")