copy() method to get a copy of a list

All list methods

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


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer