slice - Python : Why use "list[:]" when "list" refers to same thing? -


consider list >>> l=[1,2,3].

what benefit of using >>> l[:] when >>> l prints same thing former does?

thanks.

it creates (shallow) copy.

>>> l = [1,2,3] >>> m = l[:] >>> n = l >>> l.append(4) >>> m [1, 2, 3] >>> n [1, 2, 3, 4] >>> n l true >>> m l false 

Comments

Popular posts from this blog

delphi - TJvHidDeviceController "DevicePath" always showing "\" -

Disabling Android home button for industry application -

asp.net mvc 3 - Unexpected "foreach" keyword after "@" character -