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.

Answer from Shobhit Verma on Stack Overflow
🌐
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, "call by reference" is a way of handing arguments to functions where the reference to the real object gets passed instead of the object's actual value. This means that if you make changes to the object within the function, those changes ...
🌐
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
Discussions

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
How does call by reference in Python work? - Stack Overflow
Please explain when calling function first time the code follows call by reference. But when calling function second time it does not follow the same. ##functions num = [0,1,2,3,4] def first(num... More on stackoverflow.com
🌐 stackoverflow.com
How is python pass by reference different from the original "pass by reference" concapt?
This is asked very frequently. The best explanation is here: https://nedbatchelder.com/text/names.html Note that this behaviour is not specific to Python: many modern languages, such as Java, JS, Ruby, and probably more, work the same way. More on reddit.com
🌐 r/learnpython
36
20
February 27, 2022
Is Python call-by-value or call-by-reference? Neither.
The way Python treats variables is the interesting part (which the author pointed out, but I don't think it can be stressed enough). Assignment does not modify a variable; rather, it rebinds a variable. Consider this snippet: def do_something(x, y): x = 3 y[0] = 4 a = 1 b = [2] do_something(a, b) Translating this to a C-like language, it would look like this: PyObj *do_something(PyObj *x, PyObj *y) { x = &3; (*y)[0] = &4; return &None; } PyObj *a; PyObj *b; a = &1; b = &[2]; do_something(a, b); The argument passing is similar to how other languages work, but the assignment differs: b = &[2]; In some other languages, it might look more like: *b = [2]; More on reddit.com
🌐 r/Python
14
20
March 26, 2015
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
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'
🌐
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 - When Mutable objects such as list, dict, set, etc., are passed as arguments to the function call, it can be called Call by reference in Python.
🌐
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 - In Python, arguments are passed ... by assignment.” This means that when you pass an argument to a function, you are passing a reference to the object that the argument refers to....
Find elsewhere
🌐
Medium
medium.com › @pooya.oladazimi › hey-python-are-you-call-by-reference-or-value-ba3a7186ff63
Hey Python! Are you Call by Reference or Value? | by Pooya Oladazimi | Medium
February 14, 2024 - If you want to copy a refernce in Python and keep the original one, you can use the copy function ... I think at this point it becomes clear: Both. It depends on the function parameter. If the parameter is immutable such as Integer, then it is called by value.
🌐
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 - We can see even after modifying the objects state the id's of the object remains unchanged because the objects datatype are mutable objects here by ,even if the object state is modified it is treated as call by reference(call by object reference). ... Example :- Call by Value (with Immutable objects (int, float, bool, string) and object state modified) in python
🌐
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, "call by reference" is a way of handing arguments to functions where the reference to the real object gets passed instead of the object's actual value. This means that if you make changes to the object within the function, those changes ...
🌐
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-reference, the function receives reference to the argument objects passed to it by the caller, both pointing to the same memory location. you pass reference of parameters to your function.if any changes made to those parameters inside ...
🌐
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++.
🌐
Real Python
realpython.com › python-pass-by-reference
Pass by Reference in Python: Background and Best Practices – Real Python
March 18, 2026 - As you can see, the refParameter of squareRef() must be declared with the ref keyword, and you must also use the keyword when calling the function. Then the argument will be passed in by reference and can be modified in place. Python has no ref keyword or anything equivalent to it.
🌐
GeeksforGeeks
geeksforgeeks.org › pass-by-reference-vs-value-in-python
Pass by reference vs value in Python - GeeksforGeeks
August 9, 2024 - Python's argument-passing model is neither "Pass by Value" nor "Pass by Reference" but it is "Pass by Object Reference". Depending on the type of object you pass in the function, the function behaves differently.
🌐
Medium
medium.com › @namita717 › pythons-call-by-object-reference-unraveling-the-mystery-919a31e37996
Python’s Call by Object Reference: Unraveling the Mystery | by Namita | Medium
January 31, 2024 - For mutable objects like lists, the behavior appears more like call by reference. Changes made to the object inside the function are reflected in the original list outside the function. This is because the reference to the same object is passed to the function. ```python def modify_mutable(my_list): my_list.append(42) print(“Inside function:”, my_list)
🌐
TutorialsPoint
tutorialspoint.com › pass-by-reference-vs-value-in-python
Pass by reference vs value in Python
November 20, 2024 - In Python Call by Value and Call by Reference are two types of generic methods to pass parameters to a function. In the Call-by-value method, the original value cannot be changed, whereas in Call-by-reference, the original value can be changed.
🌐
Tutorial Teacher
tutorialsteacher.com › articles › how-to-pass-value-by-reference-in-python
How to pass value by reference in Python?
... def myfunction(arg): print ... myfunction(x) ... Hence, it can be inferred that in Python, a function is always called by passing a variable by reference....
🌐
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.