copy() method to get a copy of a list
copy() takes no arguments .
Returns a copy of the main list.
my_list=['Alex','Ronald','John','Ronald','Ronn']
my_list2=my_list.copy()
print(my_list2)
Output
['Alex', 'Ronald', 'John', 'Ronald', 'Ronn']
We can create a copy by selecting all the elements.
my_list=['Alex','Ronald','John','Ronald','Ronn']
my_list2=my_list[:]
print(my_list2)
Output
['Alex', 'Ronald', 'John', 'Ronald', 'Ronn']
« All list methods « Questions with solutions on List
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com