Python List copy() Method
Returns a copy of the list. The copy and the original list can then be changed separately.
Syntax
Python
Copy Code
list.copy()
Example
Python
Copy Code
groceries = ['apples', 'oranges', 'paper towels'] newGroceries = groceries.copy() newGroceries.append("tomato soup") print(f'The original grocery list: {groceries}') print(f'The new grocery list: {newGroceries}')
Output
The original grocery list: ['apples', 'oranges', 'paper towels'] The new grocery list: ['apples', 'oranges', 'paper towels', 'tomato soup']