Assignment Operators
= plus augmented forms like += -= *= /= //= %= **= &= |= and the walrus :=.
Beginner
count += 1
mask <<= 2
if (n := len(data)) > 10: # walrus: assign inside an expression (3.8+)
print(f"{n} items")
For mutable objects, a += b modifies a in place (lists extend), while a = a + b creates a new object.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.