Whatever is associated with a variable name has to be stored in the program's memory somewhere. An easy way to think of this, is that every byte of memory has an index-number. For simplicity's sake, lets imagine a simple computer, these index-numbers go from 0 (the first byte), upwards to however many bytes there are.

Say we have a sequence of 37 bytes, that a human might interpret as some words:

"The Owl and the Pussy-cat went to sea"

The computer is storing them in a contiguous block, starting at some index-position in memory. This index-position is most often called an "address". Obviously this address is absolutely just a number, the byte-number of the memory these letters are residing in.

@12000 The Owl and the Pussy-cat went to sea

So at address 12000 is a T, at 12001 an h, 12002 an e ... up to the last a at 12037.

I am labouring the point here because it's fundamental to every programming language. That 12000 is the "address" of this string. It's also a "reference" to it's location. For most intents and purposes an address is a pointer is a reference. Different languages have differing syntactic handling of these, but essentially they're the same thing - dealing with a block of data at a given number.

Python and Java try to hide this addressing as much as possible, where languages like C are quite happy to expose pointers for exactly what they are.

The take-away from this, is that an object reference is the number of where the data is stored in memory. (As is a pointer.)

Now, most programming languages distinguish between simple types: characters and numbers, and complex types: strings, lists and other compound-types. This is where the reference to an object makes a difference.

So when performing operations on simple types, they are independent, they each have their own memory for storage. Imagine the following sequence in python:

>>> a = 3
>>> b = a
>>> b
3
>>> b = 4
>>> b
4
>>> a
3      # <-- original has not changed

The variables a and b do not share the memory where their values are stored. But with a complex type:

>>> s = [ 1, 2, 3 ]
>>> t = s
>>> t
[1, 2, 3]
>>> t[1] = 8
>>> t
[1, 8, 3]
>>> s
[1, 8, 3]  # <-- original HAS changed

We assigned t to be s, but obviously in this case t is s - they share the same memory. Wait, what! Here we have found out that both s and t are a reference to the same object - they simply share (point to) the same address in memory.

One place Python differs from other languages is that it considers strings as a simple type, and these are independent, so they behave like numbers:

>>> j = 'Pussycat'
>>> k = j
>>> k
'Pussycat'
>>> k = 'Owl'
>>> j
'Pussycat'  # <-- Original has not changed

Whereas in C strings are definitely handled as complex types, and would behave like the Python list example.

The upshot of all this, is that when objects that are handled by reference are modified, all references-to this object "see" the change. So if the object is passed to a function that modifies it (i.e.: the content of memory holding the data is changed), the change is reflected outside that function too.

But if a simple type is changed, or passed to a function, it is copied to the function, so the changes are not seen in the original.

For example:

def fnA( my_list ):
    my_list.append( 'A' )

a_list = [ 'B' ]
fnA( a_list )
print( str( a_list ) )
['B', 'A']        # <-- a_list was changed inside the function

But:

def fnB( number ):
    number += 1

x = 3
fnB( x )
print( x )
3                # <-- x was NOT changed inside the function

So keeping in mind that the memory of "objects" that are used by reference is shared by all copies, and memory of simple types is not, it's fairly obvious that the two types operate differently.

Answer from Kingsley on Stack Overflow
Top answer
1 of 5
11

Whatever is associated with a variable name has to be stored in the program's memory somewhere. An easy way to think of this, is that every byte of memory has an index-number. For simplicity's sake, lets imagine a simple computer, these index-numbers go from 0 (the first byte), upwards to however many bytes there are.

Say we have a sequence of 37 bytes, that a human might interpret as some words:

"The Owl and the Pussy-cat went to sea"

The computer is storing them in a contiguous block, starting at some index-position in memory. This index-position is most often called an "address". Obviously this address is absolutely just a number, the byte-number of the memory these letters are residing in.

@12000 The Owl and the Pussy-cat went to sea

So at address 12000 is a T, at 12001 an h, 12002 an e ... up to the last a at 12037.

I am labouring the point here because it's fundamental to every programming language. That 12000 is the "address" of this string. It's also a "reference" to it's location. For most intents and purposes an address is a pointer is a reference. Different languages have differing syntactic handling of these, but essentially they're the same thing - dealing with a block of data at a given number.

Python and Java try to hide this addressing as much as possible, where languages like C are quite happy to expose pointers for exactly what they are.

The take-away from this, is that an object reference is the number of where the data is stored in memory. (As is a pointer.)

Now, most programming languages distinguish between simple types: characters and numbers, and complex types: strings, lists and other compound-types. This is where the reference to an object makes a difference.

So when performing operations on simple types, they are independent, they each have their own memory for storage. Imagine the following sequence in python:

>>> a = 3
>>> b = a
>>> b
3
>>> b = 4
>>> b
4
>>> a
3      # <-- original has not changed

The variables a and b do not share the memory where their values are stored. But with a complex type:

>>> s = [ 1, 2, 3 ]
>>> t = s
>>> t
[1, 2, 3]
>>> t[1] = 8
>>> t
[1, 8, 3]
>>> s
[1, 8, 3]  # <-- original HAS changed

We assigned t to be s, but obviously in this case t is s - they share the same memory. Wait, what! Here we have found out that both s and t are a reference to the same object - they simply share (point to) the same address in memory.

One place Python differs from other languages is that it considers strings as a simple type, and these are independent, so they behave like numbers:

>>> j = 'Pussycat'
>>> k = j
>>> k
'Pussycat'
>>> k = 'Owl'
>>> j
'Pussycat'  # <-- Original has not changed

Whereas in C strings are definitely handled as complex types, and would behave like the Python list example.

The upshot of all this, is that when objects that are handled by reference are modified, all references-to this object "see" the change. So if the object is passed to a function that modifies it (i.e.: the content of memory holding the data is changed), the change is reflected outside that function too.

But if a simple type is changed, or passed to a function, it is copied to the function, so the changes are not seen in the original.

For example:

def fnA( my_list ):
    my_list.append( 'A' )

a_list = [ 'B' ]
fnA( a_list )
print( str( a_list ) )
['B', 'A']        # <-- a_list was changed inside the function

But:

def fnB( number ):
    number += 1

x = 3
fnB( x )
print( x )
3                # <-- x was NOT changed inside the function

So keeping in mind that the memory of "objects" that are used by reference is shared by all copies, and memory of simple types is not, it's fairly obvious that the two types operate differently.

2 of 5
5

Objects are things. Generally, they're what you see on the right hand side of an equation.

Variable names (often just called "names") are references to the actual object. When a name is on the right hand side of an equation1, the object that it references is automatically looked up and used in the equation. The result of the expression on the right hand side is an object. The name on the left hand side of the equation becomes a reference to this (possibly new) object.

Note, you can have object references that aren't explicit names if you are working with container objects (like lists or dictionaries):

a = []  # the name a is a reference to a list.
a.append(12345)  # the container list holds a reference to an integer object

In a similar way, multiple names can refer to the same object:

a = []
b = a

We can demonstrate that they are the same object by looking at the id of a and b and noting that they are the same. Or, we can look at the "side-effects" of mutating the object referenced by a or b (if we mutate one, we mutate both because they reference the same object).

a.append(1)
print a, b  # look mom, both are [1]!

1More accurately, when a name is used in an expression

🌐
LabEx
labex.io › tutorials › python-how-to-understand-object-references-in-python-398254
How to understand object references in Python | LabEx
When you assign an object to a variable, you're actually creating a reference to that object. This means that the variable doesn't hold the object itself, but rather a pointer to the object's location in memory.
Discussions

How to store an object reference in a variable?
Show us your code. You're doing something wrong. More on reddit.com
🌐 r/learnpython
8
1
October 19, 2022
Are you using AWS CDK in production?
TLDR: Nope I've been playing with the CDK for the past few days and it definitely looks like the future of Infrastructure as Code (IaC) on AWS by AWS. But lack of examples, tutorials and difficult to read documentation means it will be a while before I am able to get it into prod. My initial concerns about feature lag seem to be addressed by their lower level constructs. Basically, they have higher level constructs which are fully fledged in the CDK. Clearly, there will be lag between a feature coming out, then getting introduced in CloudFormation, then getting into the CDK. They are working around it by 'publishing' Cloudformation into the CDK (not the exact wording) periodically (don't know the frequency). So, if some new resource pops up in CloudFormation (say: Bucket), you can use the class 'CfnBucket' in the CDK as soon as this 'publishing' event happens. The lowest level in the CDK is a 'CfnResource'. In this scenario, a new resource has popped up in CloudFormation but not been published into the CDK. So you can use that class and manually define CF json in that CfnResource class. The CDK is good to drive some stacks/apps to a single region/account. But, the documentation to me looks difficult to read (perhaps due to my limited experience) and the lack of examples makes the learning curve steeper and longer. I've looked at both python and typescript. Python docs are bad, the property descriptions sometimes refer to syntax examples which don't exist. And, overall I'd love to have just more syntax examples for each property type. Overall, traversing the CDK docs seem to be more of a chore than CloudFormation docs. Then we come to the CDK itself which lacks the killer feature (unless I have missed it) which would make me want to go extra mile learning the CDK and move to it asap: the ability to do cross-stack, cross-app, cross-region, cross-account (assuming the user has appropriate access) references. More on reddit.com
🌐 r/aws
38
59
July 18, 2019
How to access methods from another class ?
that's what the "self" argument is for. It passes the object on which you call the method into the method itself. So you simply write: class B(object,A): def b_function(self) print "fuction from b" self.a_function() in other words: myobj = B() myobj.a_function() is equivalent to: myobj = B() A.a_function(myobj) or: myobj = B() B.a_function(myobj) in this case. More on reddit.com
🌐 r/learnpython
8
5
February 9, 2015
Accessing object from kv-file from python (ID/Widget)
First, widget classnames must start with uppercase letters, xandy will get you in trouble.. ids are valid within a single kvlang rule. From the outside, they can only be accessed through the root widget instance (of the kvlang rule's widget tree, not referring to application root widget)... for example BoxLayout: # root widget Button: id: btn When this is instantiated, you can access the button instance with btn within the rule (everything indented below boxlayout). All the ids in the rule are collected in a single dictionary, where key is the id and corresponding widget instance is value. This dictionary lives in the root widget. So if you did x =…Builder.load_string(the_kv_above) you can do x.ids.btn (or x.ids['btn']) to access the nested child. The objectproperty thing is just creating a property to hold a widget instance, avoiding external lookup via the dict. BoxLayout: # root widget the_button: btn Button: id: btn With this you could do x.the_button instead, because that line creates a property and assigns the btn instance as value. It should be used carefully, usually ids will do the job. Since properties are class level, the previous snippet creates a property in all boxlayouts and classes that inherit from it. The better way is : new_prop: x As this only affects the MyBox subclass More on reddit.com
🌐 r/kivy
8
2
July 12, 2017
🌐
Runestone Academy
runestone.academy › ns › books › published › fopp › TransformingSequences › ObjectsandReferences.html
9.4. Objects and References — Foundations of Python Programming
In other words, the references are the same. Try our example from above. The answer is True. This tells us that both a and b refer to the same object, and that it is the second of the two reference diagrams that describes the relationship. Python assigns every object a unique id and when we ask a is b what python is really doing is checking to see if id(a) == id(b).
🌐
Medium
medium.com › @officialyrohanrokade › simplified-pythons-reference-handling-understanding-object-referencing-deleting-references-and-ae4026a74d7b
Simplified Python’s Reference Handling: Understanding Object Referencing, Deleting References, and Shallow Copying vs. Deep Copying | by Rohan Rokade | Medium
December 8, 2023 - Assigning one object to the other doesn’t spawn a new object; it establishes another reference to the same object. Modifying attributes through one reference influences the shared object, impacting both references. Reference counts serve as a fundamental part of Python’s memory management.
🌐
Python documentation
docs.python.org › 3 › reference › datamodel.html
3. Data model — Python 3.14.8 documentation
Some objects contain references to other objects; these are called containers. Examples of containers are tuples, lists and dictionaries. The references are part of a container’s value. In most cases, when we talk about the value of a container, we imply the values, not the identities of the contained objects; however, when we talk about the mutability of a container, only the identities of the immediately contained objects are implied.
🌐
freeCodeCamp
freecodecamp.org › news › how-passing-by-object-reference-works-in-python
How Passing by Object Reference Works in Python
March 26, 2026 - This is the key insight: Python doesn't decide behavior based on how you pass something, it decides based on what type of object you're passing. Python doesn't use call by value or call by reference.
🌐
Real Python
realpython.com › videos › object-references
Object References (Video) – Real Python
And even things, like, that you might not expect—like, a function is also an object in Python. 00:56 So just, everything’s an object, ha. Keep that in mind, and you’ll see why it’s important in just a second. So, what happens when we do this standard variable assignment that we talked about before? 01:06 We’re saying n = 300. Let’s head over to the IPython shell and just give it a try, put it in here, n = 300. Now I can reference 300 with the variable name n.
Published: December 10, 2019
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › how to store an object reference in a variable?
r/learnpython on Reddit: How to store an object reference in a variable?
October 19, 2022 -

Hi,

Is it possible to store the object reference instead of the value in a variable? Normally, when I do something like my_var = my_object, Python does a type conversion so that my_var becomes an str variable, leading to an attribute error like "str has no attribute ...". Is it possible to avoid that by storing the object reference itself?

🌐
Plain English
plainenglish.io › home › blog › python › pass by object reference in python
Pass By Object Reference in Python
April 21, 2022 - In Python’s Pass By Object Reference, the object reference is passed by value. A variable can be thought of as a name (or reference) assigned to an object, and the object can be mutable (eg.
🌐
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 - It is more accurately described as “call by object reference.” Understanding this concept requires exploring how Python handles variables and objects. ... In Python, variables are more like references pointing to objects in memory rather than containers holding values.
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python references
Python References
March 27, 2025 - In Python, a variable is not a label of a value as you may think. Instead, A variable references an object that holds a value.
🌐
Python
docs.python.org › 2.0 › ref › objects.html
3.1 Objects, values and types
Some objects contain references to other objects; these are called containers. Examples of containers are tuples, lists and dictionaries. The references are part of a container's value. In most cases, when we talk about the value of a container, we imply the values, not the identities of the contained objects; however, when we talk about the mutability of a container, only the identities of the immediately contained objects are implied.
🌐
Runestone Academy
runestone.academy › ns › books › published › thinkcspy › Lists › ObjectsandReferences.html
10.10. Objects and References — How to Think like a Computer Scientist: Interactive Edition
In other words, the references are the same. Try our example from above. The answer is True. This tells us that both a and b refer to the same object, and that it is the second of the two reference diagrams that describes the relationship. Since strings are immutable, Python can optimize resources by making two names that refer to the same string literal value refer to the same object.
🌐
GeeksforGeeks
geeksforgeeks.org › python › shared-reference-in-python
Shared Reference in Python - GeeksforGeeks
July 27, 2026 - A shared reference occurs when multiple variables refer to the same object in memory. Instead of creating a new object during assignment, Python creates another reference to the existing object.
🌐
Utulsa
secon.utulsa.edu › cs2123 › slides › pypass.pdf pdf
Pass by Object Reference in Python Tyler Moore CS 2123, The University of Tulsa
Pass by object reference · In Python, variables are not passed by reference or by value · Instead, the name (aka object reference) is passed · If the underlying object is mutable, then modifications to the object · will persist · If the underlying object is immutable, then changes to ...
🌐
Medium
medium.com › geekculture › python-reference-e6458a9a0582
Python — Reference
August 9, 2022 - Variables in Python have a special attribute: identity, that is, “identity identification”. This special property is also called “reference” in many places. Let’s first take a look at one example: in languages ​​such as C++, variable declaration and assignment can be separated: ... If you directly use a variable that does not exist, an error will occur, NameError: name ‘a’ is not defined · In Python, when a = 343 is executed, it first creates the object 343 in memory, and then let a point to it, which is the reference.
🌐
Plain English
python.plainenglish.io › pass-by-object-reference-in-python-79a8d92dc493
Pass By Object Reference in Python | Python in Plain English
April 22, 2022 - In Python’s Pass By Object Reference, the object reference is passed by value. A variable can be thought of as a name (or reference) assigned to an object, and the object can be mutable (eg.
🌐
Launch School
launchschool.com › books › python › read › variables_pointers
How Python objects and variables really work
The behaviors described in this ... objects. In Python, all variables are pointers to objects. If you assign the same object to multiple variables, every one of those variables references (points to) the same object....
🌐
Bite Code
bitecode.dev › bite code! › python variables, references and mutability
Python variables, references and mutability - Bite code!
September 19, 2023 - In Python, there is no "by value". Everything is "by reference". You can get a unique number that represents the object behind that reference using the id() function:
🌐
Medium
medium.com › @azadlal.lm8 › know-the-object-references-in-python-before-declaring-a-variable-b446fbb08eaa
Know the Object References in Python before declaring a variable . | by Azad | Medium
December 28, 2024 - But in python we call any variable that holds a memory address as an object. when we say object it doesn’t just mean its an instance of a class as above. everything is an object if it has a memory reference