Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save vanbasten23/0c54eaa55a3b99c042f8b6997de73d1f to your computer and use it in GitHub Desktop.

Select an option

Save vanbasten23/0c54eaa55a3b99c042f8b6997de73d1f to your computer and use it in GitHub Desktop.
```
x = [1, 2]
a = []
a.append(x)
x.append(3)
print(a)
# [[1, 2, 3]]
```
`append(x)` stores a reference to the same list object. When `x` changes later, the object inside a changes too.
You can see it with `id()`:
```
x = [1, 2]
a = []
a.append(x)
print(id(x))
print(id(a[0]))
# same number
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment