TGViewer
Python Learning Python Learning @python_bds · 5.74K subscribers
Post #1136 850
Pass by Object Reference in Python

Is Python pass-by-value or pass-by-reference? 

➡️ Actually, Python uses Pass by Object Reference.

That means:
The function receives a reference to the same object.

📌 Example: Mutable Object

def modify(lst):
    lst.append(4)

nums = [1, 2, 3]
modify(nums)

print(nums)


Output:
[1, 2, 3, 4]


👉 The original list changed 
Because the function received a reference 
to the SAME object in memory.


📌 Example: Immutable Object

def modify(x):
    x = x + 1
    print("Inside:", x)

num = 10
modify(num)

print("Outside:", num)


Output:
Inside: 11
Outside: 10


👉 Integer did not change 
Because integers are immutable 
Reassignment creates a new object.


🎯 Core Idea

• Functions receive object references 
• Mutable objects can be modified 
• Immutable objects create new objects 
• Python is NOT pure pass-by-value 
• Python is NOT pure pass-by-reference 

✅ It is Pass by Object Reference.
  • ❤ 4
More from @python_bds
  1. Oct 8, 2026🐛 This Python Bug Looks Random, But It Isn't Look at this: functions = [] for i in range(…
  2. Oct 6, 2026🐍 Python Performance Optimization Python Performance Optimization: Make Your Code Faster…
  3. Oct 4, 2026Python Set Methods ✍️
  4. Oct 3, 2026Post #1310
  5. Oct 1, 2026🐍 Python Beginner Notes
  6. Sep 30, 2026🧠 return vs print() in Python These are not interchangeable. def add(a, b): print(a + b)…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →