- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
In Python, arguments are passed by object reference (also called call by sharing). This means the function receives a reference to the same object, but reassigning the parameter inside the function won’t affect the caller’s variable — only mutating a mutable object will.
Example: Mutable vs Immutable
def modify_list(lst):lst.append(4) # in-place modificationdef reassign_list(lst):lst = [99] # rebinds local name, no effect outsidenums = [1, 2, 3]modify_list(nums)print(nums) # [1, 2, 3, 4] - changed outside tooreassign_list(nums)print(nums) # [1, 2, 3, 4] - unchangedCopied!✕CopyHere, modify_list mutates the original list (mutable), so changes persist. reassign_list points lst to a new list locally — the caller’s reference is unaffected.
Working with Immutable Types
Immutable objects (like int, str, tuple) can’t be changed in place. To “simulate” pass-by-reference for them:
Return and reassign:
def increment(x):return x + 1n = 5n = increment(n)print(n) # 6Copied!✕CopyWrap in a mutable container:
python - How do I pass a variable by reference? - Stack …
Jun 12, 2009 · Python: Python is “pass-by-object-reference”, of which it is often …
- Reviews: 16
Code sample
def use_a_wrapper_to_simulate_pass_by_reference(stuff_to_change):new_string = something_to_do_with_the_old_string(stuff_to_change[0])stuff_to_change[0] = new_stringwrapper = [my_string]use_a_wrapper_to_simulate_pass_by_reference(wrapper)...Is Python call by reference or call by value
Jul 12, 2025 · What is Call By Reference in Python? In Python, "call by reference" is a way of handing arguments to functions where the reference to the real object …
Pass by Reference in Python: Background and Best …
Aug 10, 2020 · Learn how Python handles function arguments differently from other languages and how to use mutable types to achieve pass by reference. Explore …
Call by Value vs Call by Reference in Python
Sep 6, 2025 · Learn call by value vs call by reference in Python with simple examples. Understand mutable vs immutable objects and how Python handles …
How Passing by Object Reference Works in Python
6 days ago · Python doesn't use call by value or call by reference. It passes by object reference, where the function receives a reference to the object, and whether that object can be modified in place …
Call by Value and Call by Reference in Python with Examples - Intellipaat
Jul 3, 2025 · Call by Value and Call by Reference in Python are ways to pass arguments. Learn their differences, how they work, and understand each with examples.
- People also ask
How to Call by Reference in Python - TechBloat
In Python, calling by reference means passing a variable to a function such that modifications within the function affect the original object. Understanding when and how to do this is crucial for efficient …
Python’s Call by Object Reference: Unraveling the Mystery
Jan 31, 2024 · In this blog, we’ll delve into the intricacies of Python’s argument passing mechanism, demystifying the common misconception that Python is …
Python's Pass-by-Reference: Concepts, Usage, and Best Practices
Mar 24, 2025 · This blog post will delve deep into the concept of what is commonly referred to as pass - by - reference in Python, how to use it effectively, common scenarios where it is applied, and best …
What is Call by Value and Call by Reference in Python?
Jul 7, 2024 · In this article by Scaler Topics, we will learn what Call by value and Call by reference exactly mean in Python programming language.