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

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -