Quick actions

cmd+k|ctrl+k

Navigation

Languages

mutable and immutable data

Snippet info

Language

Python

Visibility

public

Author

dnf668

Created

2025-05-15T07:10:06.347429Z

Updated

2025-05-15T08:47:57.807109Z

l = [[1,2]]
x= l +l 
print(x, id(x[0]), id(x[1]))
# [[1, 2], [1, 2]] 4567890123 4567890123  # Same `id`, meaning shared reference

x[0][0] = 10
# x> [[1, 2], [1, 2]] -- x[0] > [1,2] -- x[0][0]> 1
# Since x[0] and x[1] refer to the same inner list, modifying one affects both.
print(x)
INFO