what is the correct Syntax to copy one list into another
Answers
Answered by
5
Explanation:
A shallow copy creates a new list whose elements bind to the same objects as before.
new_list = list(my_list) # or my_list[:], but I prefer this syntax # is simply a shorter way of: new_list = [element for element in my_list] ...
import copy # each element must have __copy__ defined for this...
Answered by
0
Copy() Method
The built-in copy method is used to copy one list into another. It is available in python beginning from the Python 3.3 version. A shallow copy is made when the copy method is used.
Syntax of the copy() method:
- New_list = Old.copy()
Parameters of the copy() method:
- The copy() method doesn't take any parameters
Return Value of the copy() method:
- The copy() method returns a new list. It doesn't modify the original list.
Similar questions