Hackforge Academy

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)

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community