🌐
GeeksforGeeks
geeksforgeeks.org › python › is-python-call-by-reference-or-call-by-value
Is Python call by reference or call by value - GeeksforGeeks
July 12, 2025 - In Python, the common way of passing ... means that when you pass a variable to a function, you're essentially handing over the actual value of the variable itself, not the reference to the object it's pointing to....
🌐
Quora
quora.com › What-is-call-by-value-in-Python
What is “call by value” in Python? - Quora
Answer: There is no such thing as ‘call by value’ in Python. All arguments in Python are passed by ‘Call by Assignment’, or ‘Call by Object Reference’; what is passed around is an object reference. When you pass an immutable object as an argument - for instance a number, a string, ...
Discussions

call by value or call by reference
There's no distinction between call by value vs call by reference in python. Every name is a reference. Variables, function arguments and return values are all references. More on reddit.com
🌐 r/learnpython
18
4
November 11, 2022
python - How do I pass a variable by reference? - Stack Overflow
So it seems like parameters in Python are passed by value. Is that correct? How can I modify the code to get the effect of pass-by-reference, so that the output is Changed? Sometimes people are surprised that code like x = 1, where x is a parameter name, doesn't impact on the caller's argument, ... More on stackoverflow.com
🌐 stackoverflow.com
variables - Python functions call by reference - Stack Overflow
When you pass a parameter to a ... the value of the parameter on leaving the function.The only way to do this is by using the global reserved word (or as i understand it currently). ... k = 2 def foo (n): n = n * n #clarity regarding comment below square = n return square j = foo(k) print j print k ... In this example the variable n is changed. Is there any way in Python to call a function ... More on stackoverflow.com
🌐 stackoverflow.com
Python ist weder Call by Value noch Call by Reference
6.8M subscribers in the programming community. Computer Programming More on reddit.com
🌐 r/programming
🌐
Python Guides
pythonguides.com › python-pass-by-reference-or-value
Call by Value vs Call by Reference in Python
September 6, 2025 - Python uses call by object reference. Immutable objects (int, str, tuple) behave like call by value.
🌐
Reddit
reddit.com › r/learnpython › call by value or call by reference
r/learnpython on Reddit: call by value or call by reference
November 11, 2022 -

I'm having a difficult time understanding this concept. Suppose for example, that a function accepts a list as an argument. Does the function receive a copy of the list or does it receive a reference to the list?

Top answer
1 of 5
6
There's no distinction between call by value vs call by reference in python. Every name is a reference. Variables, function arguments and return values are all references.
2 of 5
3
I'm sick and tired of that question. So I wrote that up hoping it will forever disappear (Wishful thinking... I known...) The concept of passing by value or reference do not exist in python. The important concept in python are mutability and immutability. Variable names are not pointer to a place in memory, they are labels attached to a value that exist somewhere in memory. Multiple labels can be attached to the same value if the type of that value is immutable (int, float, string, tuple, etc). immutable example: x = 2048 # the value 2048 is created and the label 'x' is attached to it y = 2048 # the label 'y' is attached to the already existing value 2048 print(x is y) # are the label 'x' and 'y' attached to a value that reside at the same memory address? # ====> True # yes they do x = x+1 # create a new value that is 2048+1 (2049) print(x is y) # Do 2048 and 2049 reside at the same place in memory =====> False # No they don't Every time a new value is created, somewhere in memory, the label, variable name on the left side of the assignment is re-attached to that new value. Which is usually very confusing for C programmer who expect their variable to be pointers to a specific place in memory and stay that way! Immutable exemple 2: i = 0 while i < 5: print(id(i)) # show me where the value attached to i reside in memory i = i + 1 # create a new value, attached the label i to that new value # =======> 2588411691216 Every time a new value is created # =======> 2588411691248 it is created at a new place in memory # =======> 2588411691280 and the label 'i' is re-attached to that new value. # =======> 2588411691312 The memory allocated for the old values # =======> 2588411691344 will be freed by the Garbage Collector (GC) Mutable types. When you get to mutable types things are a bit different. Since they are mutable and the value can change 'in-place' a new value is created for each literal value expressed in the code: x = [1,2,3] # create a list containing the value 1,2,3 and attach the label 'x' to it y = [1,2,3] # create another list containing the value 1,2,3 and attach the label 'y' to it print(x is y) # are both labels attached to the same value? x[0] = 'a' print(x) print(y) # ======> False # No they're not # ======> ['a', 2, 3] # x has been changed # ======> [1, 2, 3] # y has not been changed # BUT x = [1,2,3] # create a list containing the value 1,2,3 and attach the label 'x' to it y = x # attached the label 'y' to the same value that 'x' is attached to print(x is y) # are both labels attached to the same value? x[0] = 'a' print(x) print(y) # ======> True # yes they are! # ======> ['a', 2, 3] # x has been changed # ======> ['a', 2, 3] # y has also been changed Arguments & Parameters When you pass parameters to a function, the arguments that it receives are transferred the same way as if you had done a argument = parameters So arguments labels attached to immutable type will be attacged to the same value, but will be re-attached to a new value if assigned to that new value. And arguments labels attached to mutable type will be attached to the same value and will stay attached to that value if it changes. Example & Proof x = 2600 lst = [1, 2, 3] def check(an_x, an_lst): global x global lst print(f"{(x is an_x)=} Labels 'x' and 'an_x' are attached to the same value in memory") print(f"{(lst is an_lst)=} Labels 'lst' abd 'an_lst' are also attached to the same value in memory ") an_x += 1 print(f"{x=}") print(f"{an_x=}") print(f"{(x is an_x)=} A new value was created and the label 'an_x' is now attached to that new value") an_lst[0] = 'a' print(f"{lst=}") print(f"{an_lst=}") print( f"{(lst is an_lst)=} The list an_lst was changed and the label 'lst' and 'an_lst' still point to the same value") check(x, lst) # OUPUT (x is an_x)=True Labels 'x' and 'an_x' are attached to the same value in memory (lst is an_lst)=True Labels 'lst' abd 'an_lst' are also attached to the same value in memory x=2600 an_x=2601 (x is an_x)=False A new value was created and the label 'an_x' is now attached to that new value lst=['a', 2, 3] an_lst=['a', 2, 3] (lst is an_lst)=True The list an_lst was changed and the label 'lst' and 'an_lst' still point to the same value Q.E.D. Edit: a few words
🌐
Rebus Community
press.rebus.community › programmingfundamentals › chapter › call-by-value-vs-call-by-reference
Call by Value vs. Call by Reference – Programming Fundamentals
December 15, 2018 - In call by value, a parameter acts within the function as a new local variable initialized to the value of the argument (a local (isolated) copy of the argument).
🌐
Medium
medium.com › @lokeshsharma596 › is-python-call-by-value-or-call-by-reference-2dd7db74dbd0
Is Python Call by Value or Call by Reference? | by Lokesh sharma | Medium
November 10, 2019 - In pass-by-value, the function receives a copy of the argument objects passed to it by the caller, stored in a new location in memory.
🌐
Scaler
scaler.com › home › topics › what is call by value and call by reference in python?
What is Call by Value and Call by Reference in Python? - Scaler Topics
July 7, 2024 - Still, if a variable refers to a mutable type, any change in the value of the mutable type will not change the memory address of the variable. Arguments are passed by assignment in Python. The assignment creates references to objects. Hence, Immutable objects passed as arguments are referred as in Call by Value and Mutable objects, when passed as arguments are referred to as Call by Reference.
🌐
Medium
medium.com › techtofreedom › python-is-neither-call-by-value-nor-call-by-reference-2a0c8f6f4a8f
Python Is Neither Call by Value Nor Call by Reference | by Yang Zhou | TechToFreedom | Medium
February 1, 2024 - In Python, the concept of “call by value” or “call by reference” doesn’t exactly apply as it does in languages like C or C++.
Find elsewhere
🌐
DEV Community
dev.to › adarshrawat7400 › how-call-by-value-and-call-by-reference-work-in-python-am2
How Call by Value and Call by Reference Work in Python? - DEV Community
November 15, 2021 - Immutable Objects Datatypes that ... **(int, float, bool, string, unicode, tuple). So when Mutable objects are passed to the function call then it is treated as **call by value.**...
🌐
IncludeHelp
includehelp.com › python › types-of-function-calling-with-examples.aspx
Python Function Call by Value and Call by Reference
In Python, call by value means passing immutable objects where changes don’t affect the original, whereas call by reference means passing mutable objects where changes can modify the original data.
🌐
Medium
medium.com › @sanwarkumarlal1111 › call-by-value-and-call-by-refrences-python-handles-in-different-ways-48a2a2b8a98b
Call by Value and Call by Reference — Python handles in a different way | by sanwar | Medium
March 25, 2024 - Conclusion Immutable objects (integers, strings, tuples) behave like call by value. Modifications within the function don’t affect the original object outside the function. Mutable objects (lists, dictionaries, sets) behave more like call by reference.
🌐
TutorialsPoint
tutorialspoint.com › pass-by-reference-vs-value-in-python
Pass by reference vs value in Python
November 20, 2024 - In the Call-by-value method, the original value cannot be changed, whereas in Call-by-reference, the original value can be changed. When we pass an argument to a function, it is stored locally (in the stack memory), i.e the scope of these variables ...
🌐
DataFlair
data-flair.training › blogs › python-program-on-call-by-value-and-return-by-value
Python Program on call by value and return by value - DataFlair
February 28, 2024 - In Python, function call by value ... data. When a function is called by value, the actual values of the arguments are passed to the function, creating a copy of the data....
🌐
GeeksforGeeks
geeksforgeeks.org › python › is-python-call-by-reference-or-call-by-value
Is Python call by reference or call by value - GeeksforGeeks
July 12, 2025 - In Python, the common way of passing ... means that when you pass a variable to a function, you're essentially handing over the actual value of the variable itself, not the reference to the object it's pointing to....
🌐
GeeksforGeeks
geeksforgeeks.org › pass-by-reference-vs-value-in-python
Pass by reference vs value in Python - GeeksforGeeks
August 9, 2024 - We pass an integer in function call_by_value(). Integers are immutable objects hence Python works according to call by value, and the changes made in the function are not reflected outside the function.
Top answer
1 of 16
3595

Arguments are passed by assignment. The rationale behind this is twofold:

  1. the parameter passed in is actually a reference to an object (but the reference is passed by value)
  2. some data types are mutable, but others aren't

So:

  • If you pass a mutable object into a method, the method gets a reference to that same object and you can mutate it to your heart's delight, but if you rebind the reference in the method, the outer scope will know nothing about it, and after you're done, the outer reference will still point at the original object.

  • If you pass an immutable object to a method, you still can't rebind the outer reference, and you can't even mutate the object.

To make it even more clear, let's have some examples.

List - a mutable type

Let's try to modify the list that was passed to a method:

def try_to_change_list_contents(the_list):
    print('got', the_list)
    the_list.append('four')
    print('changed to', the_list)

outer_list = ['one', 'two', 'three']

print('before, outer_list =', outer_list)
try_to_change_list_contents(outer_list)
print('after, outer_list =', outer_list)

Output:

before, outer_list = ['one', 'two', 'three']
got ['one', 'two', 'three']
changed to ['one', 'two', 'three', 'four']
after, outer_list = ['one', 'two', 'three', 'four']

Since the parameter passed in is a reference to outer_list, not a copy of it, we can use the mutating list methods to change it and have the changes reflected in the outer scope.

Now let's see what happens when we try to change the reference that was passed in as a parameter:

def try_to_change_list_reference(the_list):
    print('got', the_list)
    the_list = ['and', 'we', 'can', 'not', 'lie']
    print('set to', the_list)

outer_list = ['we', 'like', 'proper', 'English']

print('before, outer_list =', outer_list)
try_to_change_list_reference(outer_list)
print('after, outer_list =', outer_list)

Output:

before, outer_list = ['we', 'like', 'proper', 'English']
got ['we', 'like', 'proper', 'English']
set to ['and', 'we', 'can', 'not', 'lie']
after, outer_list = ['we', 'like', 'proper', 'English']

Since the the_list parameter was passed by value, assigning a new list to it had no effect that the code outside the method could see. The the_list was a copy of the outer_list reference, and we had the_list point to a new list, but there was no way to change where outer_list pointed.

String - an immutable type

It's immutable, so there's nothing we can do to change the contents of the string

Now, let's try to change the reference

def try_to_change_string_reference(the_string):
    print('got', the_string)
    the_string = 'In a kingdom by the sea'
    print('set to', the_string)

outer_string = 'It was many and many a year ago'

print('before, outer_string =', outer_string)
try_to_change_string_reference(outer_string)
print('after, outer_string =', outer_string)

Output:

before, outer_string = It was many and many a year ago
got It was many and many a year ago
set to In a kingdom by the sea
after, outer_string = It was many and many a year ago

Again, since the the_string parameter was passed by value, assigning a new string to it had no effect that the code outside the method could see. The the_string was a copy of the outer_string reference, and we had the_string point to a new string, but there was no way to change where outer_string pointed.

I hope this clears things up a little.

EDIT: It's been noted that this doesn't answer the question that @David originally asked, "Is there something I can do to pass the variable by actual reference?". Let's work on that.

How do we get around this?

As @Andrea's answer shows, you could return the new value. This doesn't change the way things are passed in, but does let you get the information you want back out:

def return_a_whole_new_string(the_string):
    new_string = something_to_do_with_the_old_string(the_string)
    return new_string

# then you could call it like
my_string = return_a_whole_new_string(my_string)

If you really wanted to avoid using a return value, you could create a class to hold your value and pass it into the function or use an existing class, like a list:

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_string

# then you could call it like
wrapper = [my_string]
use_a_wrapper_to_simulate_pass_by_reference(wrapper)

do_something_with(wrapper[0])

Although this seems a little cumbersome.

2 of 16
909

The problem comes from a misunderstanding of what variables are in Python. If you're used to most traditional languages, you have a mental model of what happens in the following sequence:

a = 1
a = 2

You believe that a is a memory location that stores the value 1, then is updated to store the value 2. That's not how things work in Python. Rather, a starts as a reference to an object with the value 1, then gets reassigned as a reference to an object with the value 2. Those two objects may continue to coexist even though a doesn't refer to the first one anymore; in fact they may be shared by any number of other references within the program.

When you call a function with a parameter, a new reference is created that refers to the object passed in. This is separate from the reference that was used in the function call, so there's no way to update that reference and make it refer to a new object. In your example:

def __init__(self):
    self.variable = 'Original'
    self.Change(self.variable)

def Change(self, var):
    var = 'Changed'

self.variable is a reference to the string object 'Original'. When you call Change you create a second reference var to the object. Inside the function you reassign the reference var to a different string object 'Changed', but the reference self.variable is separate and does not change.

The only way around this is to pass a mutable object. Because both references refer to the same object, any changes to the object are reflected in both places.

def __init__(self):         
    self.variable = ['Original']
    self.Change(self.variable)

def Change(self, var):
    var[0] = 'Changed'
🌐
Python Course
python-course.eu › passing_arguments.php
25. Passing Arguments | Python Tutorial | python-course.eu
Call by Value The most common strategy ... is used in C and C++, for example. In call-by-value, the argument expression is evaluated, and the result of this evaluation is bound to the corresponding variable in the function....
Top answer
1 of 12
224

There are essentially three kinds of 'function calls':

  • Pass by value
  • Pass by reference
  • Pass by object reference

Python is a pass by object reference programming language.

Firstly, it is important to understand that a variable, and the value of the variable (the object) are two separate things. The variable 'points to' the object. The variable is not the object. Again:

THE VARIABLE IS NOT THE OBJECT

Example: in the following line of code:

>>> x = []

[] is the empty list, x is a variable that points to the empty list, but x itself is not the empty list.

Consider the variable (x, in the above case) as a box, and 'the value' of the variable ([]) as the object inside the box.

Pass by object reference (Case in python)

Here, "Object references are passed by value."

def append_one(li):
    li.append(1)
x = [0]
append_one(x)
print x

Here, the statement x = [0] makes a variable x (box) that points towards the object [0].

On the function being called, a new box li is created. The contents of li are the SAME as the contents of the box x. Both the boxes contain the same object. That is, both the variables point to the same object in memory. Hence, any change to the object pointed at by li will also be reflected by the object pointed at by x.

In conclusion, the output of the above program will be:

[0, 1]

Note:

If the variable li is reassigned in the function, then li will point to a separate object in memory. x however, will continue pointing to the same object in memory it was pointing to earlier.

Example:

def append_one(li):
    li = [0, 1]
x = [0]
append_one(x)
print x

The output of the program will be:

[0]

Pass by reference

The box from the calling function is passed on to the called function. Implicitly, the contents of the box (the value of the variable) are passed on to the called function. Hence, any change to the contents of the box in the called function will be reflected in the calling function.

Pass by value

A new box is created in the called function, and copies of contents of the box from the calling function are stored into the new boxes.

2 of 12
89

You can not change an immutable object, like str or tuple, inside a function in Python, but you can do things like:

def foo(y):
  y[0] = y[0]**2

x = [5]
foo(x)
print x[0]  # prints 25

That is a weird way to go about it, however, unless you need to always square certain elements in an array.

Note that in Python, you can also return more than one value, making some of the use cases for pass by reference less important:

def foo(x, y):
   return x**2, y**2

a = 2
b = 3
a, b = foo(a, b)  # a == 4; b == 9

When you return values like that, they are being returned as a Tuple which is in turn unpacked.

edit: Another way to think about this is that, while you can't explicitly pass variables by reference in Python, you can modify the properties of objects that were passed in. In my example (and others) you can modify members of the list that was passed in. You would not, however, be able to reassign the passed in variable entirely. For instance, see the following two pieces of code look like they might do something similar, but end up with different results:

def clear_a(x):
  x = []

def clear_b(x):
  while x: x.pop()

z = [1,2,3]
clear_a(z) # z will not be changed
clear_b(z) # z will be emptied
🌐
Medium
medium.com › @gutta.sruthi1990 › call-by-value-and-call-by-reference-in-python-109a468add7f
Call by Value and Call by Reference in Python | by Gutta Sruthi | Medium
November 20, 2023 - New List 1 after append: [2, 4, ... of List1 is made · When Immutable objects such as whole numbers, strings, etc are passed as arguments to the function call, the it can be considered as Call by Value....