Skip to content

What a function can change

Watch it run · 1 of 3

A number vs a list

1def add_one(x):
2 x = x + 1
3
4def add_item(items):
5 items.append(1)
6
7n = 5
8add_one(n)
9nums = [7]
10add_item(nums)
11print(n, nums)

Memory

int n

5

Output

(nothing yet)

line 7n is 5.

step 1 of 5