The copy() method in Python is used to create a shallow copy of an object. A shallow copy of an object creates a new object with the same contents as the original object. However, any mutable objects contained within the original object are still linked to the original object. Therefore, any changes made to the mutable objects within the copy will affect the original object as well.

The copy() method is available for most built-in objects such as lists, dictionaries, sets, etc. It can also be used for user-defined objects by implementing the __copy__() method.

Here's an example of using the copy() method to create a shallow copy of a list:

original_list = [1, 2, [3, 4]] new_list = original_list.copy() new_list[0] = 5 new_list[2][0] = 6 print(original_list) # Output: [1, 2, [6, 4]] print(new_list) # Output: [5, 2, [6, 4]]


As you can see, changing the mutable object (the list [3, 4]) within the copy affects the original list as well.