+ 1

Lists question

Can someone please explain why the answer here is True False? Original question: “List1 = [1, 2] List2 = List1 List3 = List2[:] a=List2 is List1 b=List3 is List1” I added print statements: print(List1) print(List2) print(List3) and they all were printed as [1, 2] so I am a bit confused.

16th Jan 2018, 3:26 PM
Aga Bailey
Aga Bailey - avatar
1 Resposta
+ 2
list1 is actually a pointer to the list list 2 is assigned the same pointer, it points to the same array when you do [:] the interpreter is ready to take some sublist and because the indices are omitted it copies the whole list (you again get a pointer) so list1 is list2 but list3 is not list1, they just have same content
16th Jan 2018, 3:31 PM
michal