All variables in Python are references. Elementary data types aren't an exception.

In the first example, you reassign b. It no longer references the same object as a.

In the second example, you modify b. Since you've previously set a and b to be references to the same object, the modification applies to a as well.

Answer from Mark Ransom on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › reference › index.html
The Python Language Reference — Python 3.14.8 documentation
This reference manual describes the syntax and core semantics of the language. It is terse, but attempts to be exact and complete. Elsewhere, the built-in object types and functions are described in Python built-ins reference.
🌐
W3Schools
w3schools.com › python › python_reference.asp
Python Reference
This section contains a Python reference documentation.
Discussions

Understanding references in Python - Stack Overflow
How do I know whether a variable is treated like a (C++ type) reference or a plain variable? Are elementary data types just an exception to the 'everything is a reference' rule? What detail of the underlying mechanics am I missing? ... Python is not C. In python a name references an object. More on stackoverflow.com
🌐 stackoverflow.com
What's a good Python reference?
print out the official documentation. Or just make a little binder full of stuff you'll need. More on reddit.com
🌐 r/learnpython
20
11
September 29, 2023
reference - How does Python referencing work? - Stack Overflow
Much simpler: in Python, a variable is a name for an object. = is used to change what object a name refers to. The left-hand side can refer to part of an existing object, in which case the whole object is changed by replacing that part. More on stackoverflow.com
🌐 stackoverflow.com
How does python store things in lists vs integers? - Stack Overflow
v and v2 are references to the ... a and b as references to the same thing first, and then reassign a to be a reference to something else - you're not mutating 5 to be 6 (int are immutable in Python, would probably be scary if they weren't).... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python documentation
docs.python.org › 3 › reference
The Python Language Reference — Python 3.14.6 documentation
March 16, 2023 - This reference manual describes the syntax and “core semantics” of the language. It is terse, but attempts to be exact and complete. The semantics of non-essential built-in object types and of the built-in functions and modules are described in The Python Standard Library.
🌐
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.
🌐
Reddit
reddit.com › r/learnpython › what's a good python reference?
r/learnpython on Reddit: What's a good Python reference?
September 29, 2023 -

I'm going to be going to a coding competition in about a month, and we're not allowed to use any online resources, but we can bring printed material. I have some experience with Python but I still find myself googling and looking through the official documentation a fair bit. What would be a good reference I could bring?
After a little bit of googling it sounds like Fluent Python or Learning Python might be good, and I also saw someone mention Python Distilled which also sounds interesting.. I'm going to see if I can find any of these at a local bookstore or library so I can flip through them, but I don't know if maybe I'm missing something that would be a good resource to bring. I saw Think Python on the list of recommended books for this reddit which also sounds promising, although I guess I'd have to get it printed out somewhere
The competition involves some leetcode-esque programming problems, if that helps at all as far as what kind of content would be most useful.

Top answer
1 of 7
7
print out the official documentation. Or just make a little binder full of stuff you'll need.
2 of 7
5
It depends on what you mean by "reference," exactly. What do you think you're going to have to look up? How advanced is that information? Fluent Python is not a reference. It is a series of in-depth explorations of advanced topics. If what you'e going to need to look up is in the basic or intermediate categories -- basic syntax, operator precedence, what is the name of that built-in function that does such-and-such, how the object model works at a basic level -- it would be a poor choice. It's not so much a reference book as a series of extended essays on deep language topics. Here's a quick overview of the contents (based on my copy, which is the first edition, but I doubt that it's changed a whole lot since then): chapter one is an overview of how the Python object model works and how "magic" (double-underscore) methods implement functionality on user-defined object types, all focusing on a theoretical "what if we want to implement a deck of cards?" scenario. chapters 2 & 3 go over many detailed topics in sequence and container types, talking rapidly about comprehensions, generators, slicing, details of sorting, the bisect module from the standard library, alternatives to lists/arrays for heavy-duty computational work, variations on the dict type, better and worse ways to implement dict-like types yourself, how to handle missing keys in dict and related types, and how these things relate to sets. chapter four covers the str/bytes data types, how they are related, how to deal with text files when you don't know what their encoding is, practical considerations relating to string comparison and sorting, and other advanced textual topics. chapters 5-7 beat into you the notion that functions, too, are objects, and gives an overview of many of the implications of that fact; it also takes a first look at closures and function decorators. chapters 8-13 are an extended (nearly 200 pages) look at the Python object model, how variables in Python actually work at a deep level, the garbage collection model, how to build a new object type that "plays nice" with other Python objects and is easily reusable by other programmers, Python's theories of object design, protocols specifying how objects can be used and manipulated, how abstract base classes can help enforce those protocols, multiple inheritance and how to cope with it, how to use operator overloading to make user-designed objects behave like built-in objects ... and many, many implementation details on all of these topics, some of which may be relevant at some point in your life, plus many different examples of implementations of examples. chapters 14 and 15 are a grab bag of control-flow topics, covering iterables, iterators, and generators; functions designed to work with those things; the itertools module; and context managers. There's a lot of here's-a-weird-little-fact-you-should-know moments, plus a lot of setup for chapters 16-18. chapter 16-18 are about coroutines, which are a way of structuring control flow that is very different from simply iterating, branching, and calling functions in the way that you're used to doing. Coroutines can be super-useful in some ways but aren't needed everywhere; these three chapters give you a solid introduction including two different deep dives into implementations in different contexts. Chapter 19 talks about object attributes a lot. It also gives an introduction to properties, which behave like attributes but run code to return a value instead of just looking up a value from an attribute name, plus a lot of implementation details. Chapter 20 generalizes properties to descriptors, a much more general version of the idea, and shows the best examples I've seen of how they are useful in real-world projects. Chapter 21 will be very helpful if you ever need to programmatically generate, rather than code manually, not objects, but object classes. Like everything in Python, classes are themselves objects that can be created and manipulated at runtime. There's also a brief afterward. So it's a great book, and it's totally worth reading several times and thinking about, but it's not useful as a reference unless you think you'll need to look up stuff in that list of topics. There are thousands of Python topics that are not covered in it, though. Learning Python is a good, long, detailed read, and it's plausible that you could use it as a reference, but it would be helpful to know the book decently well first, because it's ~1600 pages and finding what you're looking for can take a while even with the index's help. It's also fairly dated at this point: the last version I think covers Python 3.3, with the occasional look forward to Python 3.4. The basics of Python since then are (mostly) very much the same, and probably 90% of the changes are in the "we've added even more good stuff" category, but some of Lutz's material, examples, and code looks odd these days because he's (e.g.) using the os and shutil modules instead of the more modern pathlib. That old code will still work, but there are neater, more elegant, shorter ways to do it now.
🌐
Medium
medium.com › geekculture › python-reference-e6458a9a0582
Python — Reference
August 9, 2022 - In Python, a variable is not a label of value like you may think. Instead, a reference in python means a different name for a memory location that has been associated.
Find elsewhere
🌐
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 - This mechanism allows Python to automatically handle memory deallocation, optimize resources, and manage object lifecycles effectively. Shallow copying creates a new object with references to the original, affecting only the top-level elements, while deep copying generates a replica, including all nested structures, ensuring complete independence.
🌐
Bite Code
bitecode.dev › bite code! › python variables, references and mutability
Python variables, references and mutability - Bite code!
September 19, 2023 - Again, many programming languages can pass things either by reference or by value. "By value" is a copy. "By reference" passes the information of where to get the thing you are talking about. In Python, there is no "by value".
🌐
Python
wiki.python.org › moin › ReferenceBooks
ReferenceBooks - Python Wiki
This is a printed edition of the official Python language reference manual by Guido van Rossum.
🌐
BrainStation®
brainstation.io › learn › python › reference
Python Reference Documentation (2026 Tutorial) | BrainStation®
February 4, 2025 - This reference guide will provide an introduction to the Python programming language for beginners, with an overview of key Python syntax, concepts, and terminology.
🌐
Python
docs.python.org › 3.13 › reference › index.html
The Python Language Reference — Python 3.13.15 documentation
This reference manual describes the syntax and “core semantics” of the language. It is terse, but attempts to be exact and complete. The semantics of non-essential built-in object types and of the built-in functions and modules are described in The Python Standard Library.
🌐
GitHub
github.com › justmarkham › python-reference
GitHub - justmarkham/python-reference: Python Quick Reference · GitHub
This is the reference guide to Python that I wish had existed when I was learning the language.
Author: justmarkham
🌐
CodeRivers
coderivers.org › blog › python-references
Python References: Unveiling the Basics, Usage, and Best Practices - CodeRivers
February 22, 2026 - References vs. Values ... In Python, a reference is a name that refers to an object. Every object in Python has a unique identity, and variables are simply references to these objects.
🌐
Runestone Academy
runestone.academy › ns › books › published › fopp › TransformingSequences › ObjectsandReferences.html
9.4. Objects and References — Foundations of Python Programming
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).
🌐
O'Reilly
oreilly.com › library › view › python-in-a › 0596001886 › ch04s03.html
Variables and Other References - Python in a Nutshell [Book]
March 3, 2003 - Variables and Other References A Python program accesses data values through references. A reference is a name that refers to the specific location in memory of a value (object).... - Selection from Python in a Nutshell [Book]
Author: Alex Martelli
Published: 2003
Pages: 656
🌐
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.
Top answer
1 of 1
3

Your original question is really asking about two different things.

The first is this, with some annotation - you ask about lists. Lists are objects that are mutable sequences, and in your code, v and v2 always refer to the same list. You can modify the contents of the list using any referrer to it and those changes are visible to anything that refers to it.

v = [0,0,0,0] # create a list object and assign reference to v

v2 = v        # assign v2 to be the reference to list v also refers to

v[0]=5        # modify first list element

print(v2)     # print the list v2 refers to, which is the same list v refers to

In the second piece of code you show, you're changing what a variable refers to, rather than changing the underlying value of an object.

a=5      # Assign a to be a reference to 5

b=a      # Assign b to be a reference to the thing a refers to

a=6      # Re-assign a to refer to 6, a now refers to a different object than b

print(b) # b still refers to 5

And you pointed out the use of id. I will also introduce sys.getrefcount() which lets you see what the reference count for any particular object is, so we can see that, say, v's referred-to list has multiple things referring to it.

import sys

v = [0,0,0,0] 

v2 = v        

v[0]=5        

print(f"id(v) = {id(v)}")
print(f"id(v2) = {id(v2)}")

# this shows 3 instead of 2 because getrefcount(x)
# increases refcount of x by 1
print(f"v referrers: {sys.getrefcount(v)}")

del v2 # remove v2 as a reference

# and this will show 2 because v2 doesn't
# exist/doesn't refer to it anymore
print(f"v referrers: {sys.getrefcount(v)}")

a = 5
b = 5
print(f"id(a) = {id(a)}")
print(f"id(b) = {id(b)}")

# you're reassigning a here, so the id will change
# but you didn't change what b refers to
a = 6
print(f"id(a) = {id(a)}")
print(f"id(b) = {id(b)}")

And the output of this would look something like this...

id(v) = 4366332480
id(v2) = 4366332480
v referrers: 3
v referrers: 2

id(a) = 4365582704
id(b) = 4365582704
id(a) = 4365582736
id(b) = 4365582704

And as I mentioned - CPython does some special stuff for numbers in the range of [-5, 256] and keeps a static list of them in memory, so id on any integer in that range should return the same value for any referrers to them.