Python List: copy() Method
copy() Method
The copy() method returns a copy of a given list.
Visual Explanation:

Syntax:
new_list = list.copy()
Parameter: No parameters
Return Value from clear() method
Returns a new list. It doesn't modify the original list.
Equivalent Command of copy() method:
a[:]
Example 1: Copying a List
# colors list
colors = ['Red', 'Green', 'Black']
print("Original list:")
print(colors)
print("Copying the said list:")
new_colors = colors.copy()
print("Add an element to list:")
new_colors.append('White')
print("New list:",new_colors)
Output:
Original list: ['Red', 'Green', 'Black'] Copying the said list: Add an element to list: New list: ['Red', 'Green', 'Black', 'White']
Example 2: Copy List using slicing syntax
# colors list
colors = ['Red', 'Green', 'Black']
print("Original list:")
print(colors)
print("Copying the said list:")
new_colors = colors[:]
print("Add an element to list:")
new_colors.append('White')
print("New list:",new_colors)
Output:
Original list: ['Red', 'Green', 'Black'] Copying the said list: Add an element to list: New list: ['Red', 'Green', 'Black', 'White']
Python Code Editor:
Previous: Python List clear() Method.
Next: Python List count() Method.
Test your Python skills with w3resource's quiz
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join