copy

list.copy

Returns a shallow copy of the list — a new list containing the same element references. Equivalent to lst[:] or list(lst); does not recursively copy nested mutables.

list.copy()

Parameters

Parameter Purpose
(no args) copy() takes no arguments.
shallow only For nested lists/dicts, use copy.deepcopy() to duplicate the inner objects too.

Examples

>>> a = [1, 2, 3]
>>> b = a.copy()
>>> b.append(4)
>>> a
[1, 2, 3]

Independent top-level lists.

>>> a = [[1, 2], [3]]
>>> b = a.copy()
>>> b[0].append(99)
>>> a
[[1, 2, 99], [3]]

Shallow — the inner list is shared between a and b.

>>> import copy
>>> b = copy.deepcopy(a)

deepcopy fully clones nested structures.

>>> a = [1, 2]; b = a[:]
>>> b is a
False

lst[:] and list(lst) are the classical shallow-copy idioms.

Gotcha

It is a SHALLOW copy — nested mutables (lists, dicts, objects) are still shared with the original. Use copy.deepcopy for a fully independent tree.

Related methods

← All Python list methods · Dict methods · list vs tuple vs set