Search⌘ K
AI Features

Puzzle 27: Explanation

Explore how Python executes augmented assignments such as += by distinguishing between rebinding and in-place mutation. Understand special methods like __iadd__ and why functional programming avoids mutating passed objects. This lesson helps you clarify Python's behavior with lists and ranges and improve your coding approach.

We'll cover the following...

Try it yourself

...
Python 3.8
def add_n(items, n):
items += range(n)
items = [1]
add_n(items, 3)
print(items)

In ...

Ask