<jupyter_start><jupyter_text>All the IPython Notebooks in this lecture series by Dr. <NAME> are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/003_Python_List_Methods)**  Python List `copy()`The **`copy()`** method returns a shallow copy of the list.A **[list](https://github.com/milaan9/02_Python_Datatypes/blob/main/003_Python_List.ipynb)** can be copied using the **`=`** operator. For example,<jupyter_code>old_list = [1, 2, 3]
new_list = old_list
print('old_list:', old_list)
print('new_list:', new_list)<jupyter_output>old_list: [1, 2, 3]
new_list: [1, 2, 3]<jupyter_text>The problem with copying lists in this way is that if you modify **`new_list`**, **`old_list`** is also modified. It is because the new list is referencing or pointing to the same **`old_list`** object.<jupyter_code>old_list = [1, 2, 3]
new_list = old_list

# add an element to list
new_list.append('a')

print('New List:', new_list)
print('Old List:', old_list)<jupyter_output>New List: [1, 2, 3, 'a']
Old List: [1, 2, 3, 'a']<jupyter_text>However, if you need the original list unchanged when the new list is modified, you can use the **`copy()`** method.>Related tutorial: **[Python Shallow Copy Vs Deep Copy](https://github.com/milaan9/02_Python_Datatypes/blob/main/003_Python_List_Methods/Python_Shallow_Copy_and_Deep_Copy.ipynb)** **Syntax**:```pythonnew_list = list.copy()```  `copy()` ParametersThe **`copy()`** method doesn't take any parameters.  Return Value from `copy()`The **`copy()`** method returns a new list. It doesn't modify the original list.<jupyter_code># Example 1: Copying a List

# mixed list
my_list = ['cat', 0, 6.7]

# copying a list
new_list = my_list.copy()

print('Copied List:', new_list)<jupyter_output>Copied List: ['cat', 0, 6.7]<jupyter_text>If you modify the **`new_list`** in the above example, **`my_list`** will not be modified.<jupyter_code># Copy List Using Slicing Syntax

# shallow copy using the slicing syntax

# mixed list
list = ['cat', 0, 6.7]

# copying a list using slicing
new_list = list[:]

# Adding an element to the new list
new_list.append('dog')

# Printing new and old list
print('Old List:', list)
print('New List:', new_list)<jupyter_output>Old List: ['cat', 0, 6.7]
New List: ['cat', 0, 6.7, 'dog']
{'fraction_non_alphanumeric': 0.15404929577464788, 'fraction_numerical': 0.022887323943661973, 'mean_word_length': 5.887878787878788, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '4520', 'license': 'MIT', 'n_tokens_mistral': 870, 'n_tokens_neox': 804, 'n_words': 252, 'path': '003_Python_List_Methods/010_Python_List_copy().ipynb', 'repo_name': 'Maxc390/python-discrete-structures', 'size': '2278'}