7

When I run

x = [0, 1]
y = [2, 3]
x.append(y)
x[2][1] = 4
print y

it prints out

[2, 4]

So, basically, is it appending the reference of the argument to the list? not a copy that is totally unrelated to the argument?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Anj
  • 115
  • 2
  • 10
  • 2
    Python names and list contents are references, and unless documented otherwise, no copies are created when you pass a name to a method. This applies just as much to `list.append()` as to any other call; `list.append()` adds a reference to the list, not a copy. – Martijn Pieters Apr 08 '17 at 09:15
  • 4
    You may also be interested in reading [this excellent article on Python names and values](https://nedbatchelder.com/text/names.html). – Martijn Pieters Apr 08 '17 at 09:18

0 Answers0