The method copy()
makes a shallow copy of the list, but I don't see any point in using it, if I want to make a copy of the list I just do:
lista2 = lista1
Instead of:
lista2 = lista1.copy()
What is the method for copy()
?
The method copy()
makes a shallow copy of the list, but I don't see any point in using it, if I want to make a copy of the list I just do:
lista2 = lista1
Instead of:
lista2 = lista1.copy()
What is the method for copy()
?
When you assign one list to another, what you're doing is passing a reference to the first list. instead, with a copy you create a new stand-alone instance.