Python - Copy Lists
Python - Copy Lists
Dark mode
Dark code
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP BOOTSTRAP HOW TO W3.CSS C C++ C# REACT R JQUERY DJANGO
yt o to
Python Get Started
ADVERTISEMENT
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Numbers
Python Casting
Python - Copy Lists
Python Strings
Python Booleans
❮ Previous Next ❯
Python Operators
Python Lists
Python Lists Copy a List
Access List Items
You cannot copy a list simply by typing list2 = list1 , because: list2 will only be a reference to list1 , and changes made in
Change List Items
list1 will automatically also be made in list2 .
Add List Items
Remove List Items There are ways to make a copy, one way is to use the built-in List method copy() .
Loop Lists
List Comprehension
Example Get your own Python Server
Sort Lists
Copy Lists Make a copy of a list with the copy() method:
Join Lists
thislist = ["apple", "banana", "cherry"]
List Methods mylist = thislist.copy()
List Exercises print(mylist)
Python Tuples
Try it Yourself »
Example
Make a copy of a list with the list() method:
ADVERTISEMENT
ADVERTISEMENT
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.