There's no way you can do that changing only that line. You can do:

a = [1]
b = a
a[0] = 2
b[0]

That creates a list, assigns the reference to a, then b also, uses the a reference to set the first element to 2, then accesses using the b reference variable.

Answer from Matthew Flaschen on Stack Overflow
Top answer
1 of 11
89

There's no way you can do that changing only that line. You can do:

a = [1]
b = a
a[0] = 2
b[0]

That creates a list, assigns the reference to a, then b also, uses the a reference to set the first element to 2, then accesses using the b reference variable.

2 of 11
55

I want form.data['field'] and form.field.value to always have the same value

This is feasible, because it involves decorated names and indexing -- i.e., completely different constructs from the barenames a and b that you're asking about, and for with your request is utterly impossible. Why ask for something impossible and totally different from the (possible) thing you actually want?!

Maybe you don't realize how drastically different barenames and decorated names are. When you refer to a barename a, you're getting exactly the object a was last bound to in this scope (or an exception if it wasn't bound in this scope) -- this is such a deep and fundamental aspect of Python that it can't possibly be subverted. When you refer to a decorated name x.y, you're asking an object (the object x refers to) to please supply "the y attribute" -- and in response to that request, the object can perform totally arbitrary computations (and indexing is quite similar: it also allows arbitrary computations to be performed in response).

Now, your "actual desiderata" example is mysterious because in each case two levels of indexing or attribute-getting are involved, so the subtlety you crave could be introduced in many ways. What other attributes is form.field suppose to have, for example, besides value? Without that further .value computations, possibilities would include:

class Form(object):
   ...
   def __getattr__(self, name):
       return self.data[name]

and

class Form(object):
   ...
   @property
   def data(self):
       return self.__dict__

The presence of .value suggests picking the first form, plus a kind-of-useless wrapper:

class KouWrap(object):
   def __init__(self, value):
       self.value = value

class Form(object):
   ...
   def __getattr__(self, name):
       return KouWrap(self.data[name])

If assignments such form.field.value = 23 is also supposed to set the entry in form.data, then the wrapper must become more complex indeed, and not all that useless:

class MciWrap(object):
   def __init__(self, data, k):
       self._data = data
       self._k = k
   @property
   def value(self):
       return self._data[self._k]
   @value.setter
   def value(self, v)
       self._data[self._k] = v

class Form(object):
   ...
   def __getattr__(self, name):
       return MciWrap(self.data, name)

The latter example is roughly as close as it gets, in Python, to the sense of "a pointer" as you seem to want -- but it's crucial to understand that such subtleties can ever only work with indexing and/or decorated names, never with barenames as you originally asked!

🌐
Real Python
realpython.com › pointers-in-python
Pointers in Python: What's the Point? – Real Python
March 18, 2026 - In this step-by-step tutorial, you'll get a clearer understanding of Python's object model and learn why pointers don't really exist in Python. You'll also cover ways to simulate pointers in Python without the memory-management nightmare.
🌐
GeeksforGeeks
geeksforgeeks.org › python › using-pointers-in-python-using-ctypes
Using Pointers in Python using ctypes - GeeksforGeeks
July 23, 2025 - As the name suggests void pointer is a type of Pointer that has no specific data type associated with it. It can be typecasted into any type and can hold data of any type. Since in Python the concept of pointers is not properly available or used we can't properly create a Void Pointer, as the POINTER function requires one argument i.e the data type.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › pointers in python
Pointers in Python | Type of Pointers | Arithmetic Operations
August 23, 2025 - Let us look now with an example ... address. ... In this example, we are declaring two variables, x and y, where y is equal to x, which now points to the same memory address as that of x....
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
LearnXbyExample
learnxbyexample.com › learn x by example › python programming › pointers in python
Pointers in Python | Learn X By Example
September 21, 2024 - Lists are mutable in Python, so changes made inside the function affect the original list. In the main function, we first use an integer to show that zero_value doesn’t change the original value. Then we use a list to show that zero_reference does change the original value. Finally, we print the id of the integer, which is somewhat analogous to printing a memory address in languages with explicit pointers.
🌐
Nickmccullum
nickmccullum.com › python-pointers
How to Use Python Pointers | Nick McCullum
June 13, 2020 - Examples of Python types include int, float, string, and boolean. Value is the actual value of the object that is stored in the memory. Objects in Python are of two types – Immutable and Mutable. It is important to understand the difference between immutable and mutable objects to implement pointer behavior in Python.
🌐
Ned Batchelder
nedbatchelder.com › blog › 202403 › does_python_have_pointers
Does Python have pointers? | Ned Batchelder
March 11, 2024 - I think the power of pointers lies in referring to an object without making a copy. In your Python example, there is a copy of the object because integers are immutable.
Find elsewhere
🌐
Anvil
anvil.works › articles › pointers-in-my-python-1
Memory Management in Python - Part 1: What Are Pointers?
For the purposes of this series of articles, we don’t need to worry about scopes; we can assume all our examples take place in the global namespace. Pointers can be thought of as names - that is, entries in Python’s namespace - that correspond to objects in Python’s memory.
🌐
CodeSpeedy
codespeedy.com › home › understanding pointers in python
Understanding Pointers In Python - CodeSpeedy
January 30, 2020 - This shows us the example of a Pointer. Whereas on the other hand when we will consider ” x ” to be 10 which comes under the basic category of variable as explained earlier and does the following changes: ... We will still get ” y ” to be the integer value of 10 as output. This shows the concept of Pointers in Python with respect to basic and non-basic variables.
🌐
Scaler
scaler.com › home › topics › do we have pointers in python?
Do We Have Pointers in Python? - Scaler Topics
May 4, 2023 - We can use the Python custom class in place of the dictionary. Let's take a look at an example. In the above code, the Pointer class is defined. In the _metrics member variable, this class used dict to store actual data. It will give our program flexibility.
🌐
TutorialsPoint
tutorialspoint.com › article › what-is-the-pointer-in-python-does-a-pointer-exist-in-python
What is the Pointer in Python? Does a Pointer Exist in Python?
April 4, 2023 - Python uses automatic garbage collection to manage memory. The garbage collector automatically deallocates objects when no variables reference them, eliminating the need for manual memory management like in C or C++. Python doesn't have explicit pointers like C or C++, but uses references to manage object access.
🌐
Medium
medium.com › @rajsigh717 › python-interview-two-pointer-technique-5c4e3259a909
Python Interview — Two Pointer technique
February 27, 2024 - ... Leet code# 125- Valid Palindrome Example 1: Input: s = “A man, a plan, a canal: Panama” Output: true Explanation: “amanaplanacanalpanama” is a palindrome. Remove all the spaces, non alphanumeric and special character and then compare ...
🌐
Launch School
launchschool.com › books › python › read › variables_pointers
How Python objects and variables really work
Thus, when you access a variable, Python first determines where the variable is on the stack. It then takes the object's heap address from the stack item and uses it to find the object. The variable is a pointer to a stack location, and the stack location is a pointer to the object. Let's break that down with an example. Assume we're creating a variable named numbers and giving it an initial value of a list with 3 numbers:
🌐
Python Morsels
pythonmorsels.com › variables-are-pointers
Variables are pointers in Python - Python Morsels
July 18, 2026 - An assignment in Python points a variable to an object. That's it! Variables don't contain objects, and nothing gets implicitly copied during an assignment. Instead of thinking of variables as buckets that contain objects, think of them as bindings, references, aliases, or pointers.
🌐
Practicaldatascience
practicaldatascience.org › notebooks › class_2 › week_3 › 13_objects_and_variables.html
Variables are pointers to objects — Practical Data Science with Python
The variable associated with that list (say, my_array) actually just stores the location of the shelf where that list was placed (which we call a reference or a pointer). This is represented in the figure below in “b”. Whenever we show arrays, we’re taking som liberties by representing them as shown in a to make the figures a bit simpler / more concise. In reality, what’s always going on is what’s shown in b.
🌐
Pyvideo
pyvideo.org › pycon-us-2024 › pointers-in-python.html
PyVideo.org · Pointers in Python
May 16, 2024 - Remember pointers from C/C++? Why don’t we add them to Python? Make any Python object mutable by manipulating it directly in memory through the pointer as you would do in C/C++. Why do this? Well, pointers have no use in Python, but the point is not implementation itself, but all the internal ...
🌐
YouTube
youtube.com › watch
Pointers in Python Are A Real Thing - YouTube
In this video, we learn how to use C-pointers in Python.◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾📚 Programming Books & Merch 📚🐍 The Python Bible Book: https://www.neuralnine.com/...
Published: December 13, 2022
🌐
Quora
quora.com › How-do-you-work-with-pointers-in-Python
How to work with pointers in Python - Quora
Answer (1 of 6): You can’t work with a arbitrary pointer into memory (as you can in C or C++; there isn’t the equivalent of malloc or realloc. Having said that when you do something like [code]a = 3 [/code]The name a is now associated with a reference (a smart pointer) to an integer object, ...