Category: python
Variables Refer to Objects
Published on 27 Oct 2026
Explanation
Python names are bound to objects, which have a type and identity.
Code:
number = 100 name = 'Python' print(type(number), type(name)) print(id(number))
Explanation
Assignment binds another name to the same object; it does not automatically copy the object.
Code:
first = [1, 2] second = first second.append(3) print(first)
Explanation
Reassignment changes which object a name refers to; it does not mutate the object previously referenced.
Code:
first = [1, 2] second = first first = [4, 5] print(first, second)
Explanation
id() returns an object's identity during its lifetime. Use is to test identity rather than relying on numeric IDs.
Code:
a = [1, 2] b = a c = [1, 2] print(a is b, a is c)
Explanation
A parameter is a local name for the passed object. Mutating a shared list affects the caller's object; rebinding the parameter does not.
Code:
def modify(items):
items.append(4)
nums = [1, 2, 3]
modify(nums)
print(nums)