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

🌐
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).
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
Can someone explain the g object in Flask? I've read through the docs and searched, but I'm still stuck
Occasionally you might find a situation in which using a global variable is a perfectly reasonable solution to a problem. However, in a Flask app, your code is likely to end up running in an environment with multiple requests being handled at the same time. If you used a normal global variable, one request might modify the global variable and interfere with another request that happens to be executing simultaneously. To avoid that, Flask provides this g object to which you can attach such variables. Each request gets a different g object, so simultaneous requests can't interfere with each other, but you still have the same convenience as a global variable. More on reddit.com
🌐 r/learnpython
4
2
February 16, 2016
What is the best practice in Python for implementing a Data Access Object pattern?
the best idea is to unlearn eveything you have learned from using java More on reddit.com
🌐 r/Python
17
5
March 7, 2011
🌐
LabEx
labex.io › tutorials › python-how-to-understand-object-references-in-python-398254
How to understand object references in Python | LabEx
Lists are mutable objects in Python, which means that you can modify them directly through object references. Let's see an example:
🌐
Real Python
realpython.com › videos › object-references
Object References (Video) – Real Python
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.
Published: December 10, 2019
🌐
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.
🌐
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. In other words, variables are references. The following example assigns a number with the value of 100 to a variable:
🌐
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 - These references enable Python to manage memory efficiently. Picture your objects: obj1, and obj2, as secret agents on a top mission. When you link obj2 = obj1, they’re like two agents sharing the same mission dossier.
Find elsewhere
🌐
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.
🌐
Medium
medium.com › geekculture › python-reference-e6458a9a0582
Python — Reference
August 9, 2022 - Let’s first take a look at one ... 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....
🌐
Tudelft
oit.tudelft.nl › learn-python › 2025 › objects › nutshell › object.html
4.1. Objects and References — Python for Civil Engineers
In this example, two dictionaries person1 and person2 are created, representing people with a name attribute. Assigning person1 to person2 makes both variables refer to the same dictionary object.
🌐
Python documentation
docs.python.org › 3 › reference › datamodel.html
3. Data model — Python 3.14.8 documentation
This method returns a list of all those references still alive. The list is in definition order. Example: >>> class A: pass >>> class B(A): pass >>> A.__subclasses__() [<class 'B'>] A class instance is created by calling a class object (see above). A class instance has a namespace implemented as a dictionary which is the first place in which attribute references are searched.
🌐
Useful
useful.codes › objects-and-references-in-python
Objects and References in Python | Useful Codes
For example: ... Here, a new list object is created in memory. Usage: Objects can be used, modified, and interacted with throughout their lifespan. They remain in memory as long as there are references to them.
🌐
Plain English
plainenglish.io › home › blog › python › pass by object reference in python
Pass By Object Reference in Python
April 21, 2022 - Pass By Reference, where a reference to the original value is passed as the parameter and so the original value in the caller is also modified. 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.
🌐
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:
🌐
GeeksforGeeks
geeksforgeeks.org › python › shared-reference-in-python
Shared Reference in Python - GeeksforGeeks
July 27, 2026 - Python may reuse the same object for small integers. ... Therefore, is may also return True. Note: Object caching is an implementation detail and should not be relied upon in programs. Use == for value comparisons and reserve is for identity checks (for example, value is None).
🌐
Daniel Michaels
danielms.site › blog › python-object-references
Daniel Michaels | Python Object References
July 9, 2018 - Instead of “boxes” it is better to think of variables as “labels” that we attach to objects. And, as everything in python is an object its important to remember that all objects have three things; identity, type and values.
🌐
Quora
quora.com › In-Python-what-exactly-is-the-difference-between-a-variable-an-object-and-a-reference
In Python, what exactly is the difference between a variable, an object, and a reference? - Quora
Answer (1 of 3): Here’s my understanding, with perhaps an over-reliance on details specific to CPython for part of it. An object has a type (such as [code ]int[/code] or a particular class), and a value. Each object instance also has a unique identity. The type and value aren’t necessarily ...
🌐
FavTutor
favtutor.com › blogs › pass-by-reference-in-python
Pass by Reference in Python | With Examples
October 7, 2023 - In this example, my_list is passed to the modify_list_ref function, and changes made within the function are reflected in the original list. In Python, everything is an object, including variables.
🌐
Launch School
launchschool.com › books › python › read › variables_pointers
How Python objects and variables really work
The behaviors described in this chapter arise from the interaction of variables using pointers to reference their associated 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.
🌐
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 - This is because, in reality, a new object is created when the value is modified, and the reference is reassigned. ```python def modify_immutable(x): x = x + 1 print(“Inside function:”, x)