You are on page 1of 2

Mutation vs.

Construction

Mutating the List Constructing the List


indexed assignment (lst[i] = x) list literals ([1, 2, 3], [])
append method list constructor (list(x))
insert method copy.copy()
pop method copy.deepcopy()
reverse method + operator
sort method * operator
slicing (lst[ __ : __])
list comprehension

● stores the copy of the original object and points the references to the objects

● import copy → copy.copy(x)

● lst.copy()

● + operator

● * operator

● by default, most python operations are shallow copy (default copy.copy is shallow)
● stores the copy of the original object and recursively copies the objects as well

● import copy → copy.deepcopy(x [,memo])

When copying a compound object, like a list or dictionary, shallow copy makes a copy of the

compound object and makes references to the objects in the compound object. Deep copy makes

a copy of the compound object and all the objects in the compound object.

You might also like