0
x = [1,2,3,4,5] x.append(x[:]) print(len(x)) # output:6 # i was thinking the len should be 10 why 6?
3 odpowiedzi
+ 4
<x> will be [ 1, 2, 3, 4, 5, [ 1, 2, 3, 4, 5 ] ]
5 original items, and 1 list object
+ 2
x[ : ] means to create a new list object, copy all items from <x>. But it is a different object, not a reference copy.
That is why the 6-th element is a list object (a copy of <x>)
There's a chapter in the tutorial
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/
+ 1
Ipang please explain well give me details