There's no concept of pointers on python (at least that I'm aware of).

In case you are saving objects inside your list, you can simply keep a reference to that object.

In the case you are saving primitive values into your list, the approach I would take is to make a wrapper object around the value/values and keep a reference of that object to use it later without having to access the list. This way your wrapper is working as a mutable object and can be modified no matter from where you are accesing it.

An example:

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

# save an object into a list
l = []
obj = FooWrapper(5)
l.append(obj)

# add another object, so the initial object is shifted
l.insert(0, FooWrapper(1))

# change the value of the initial object
obj.value = 3
print l[1].value # prints 3 since it's still the same reference
Answer from asermax on Stack Overflow
Top answer
1 of 2
15

There's no concept of pointers on python (at least that I'm aware of).

In case you are saving objects inside your list, you can simply keep a reference to that object.

In the case you are saving primitive values into your list, the approach I would take is to make a wrapper object around the value/values and keep a reference of that object to use it later without having to access the list. This way your wrapper is working as a mutable object and can be modified no matter from where you are accesing it.

An example:

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

# save an object into a list
l = []
obj = FooWrapper(5)
l.append(obj)

# add another object, so the initial object is shifted
l.insert(0, FooWrapper(1))

# change the value of the initial object
obj.value = 3
print l[1].value # prints 3 since it's still the same reference
2 of 2
1

element = mylist[0] already works if you don't need to change the element or if element is a mutable object.

Immutable objects such as int objects in Python you can not change. Moreover, you can refer to the same object using multiple names in Python e.g., sys.getrefcount(1) is ~2000 in a fresh REPL on my system. Naturally, you don't want 1 to mean 2 all of a sudden in all these places.

If you want to change an object later then it should be mutable e.g., if mylist[0] == [1] then to change the value, you could set element[0] = 2. A custom object instead of the [1] list could be more appropriate for a specific application.

As an alternative, you could use a dictionary (or other namespace objects such as types.SimpleNamespace) instead of the mylist list. Then to change the item, reference it by its name: mydict["a"] = 2.

๐ŸŒ
Quora
quora.com โ€บ Does-Python-list-store-pointers-to-the-actual-array-items
Does Python list store pointers to the actual array items? - Quora
Answer (1 of 3): What I understood from the question was whether items are added to the list as a reference or just a value i.e pass-by-value or pass-by-reference. Actually, it depends on the type of the item. First letโ€™s assume the item is integer [code]>>> a = 5 >>> b = 4 >>> c = [a, b] >>> ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ why doesn't python have pointers?
r/learnpython on Reddit: Why doesn't Python have pointers?
April 21, 2023 -

No, really. I've just started practicing problems on Leetcode and today I tried to do a bunch of things with Linked lists in python. I always second guess myself when I'm writing assignment statements like node = next_node because I'm worried that using shallow copies might screw things up for me.

Wouldn't it have been way easier to directly reference objects by their memory location?

I'm not going to use C for coding interviews so I'd also appreciate any ways I can idiot proof my code when I'm dealing with moving and assigning objects in Python.

One idea I had was to include a deepcopy method in the List node class definition but I can't make any changes to the leetcode question setup.

Top answer
1 of 28
219
Because itโ€™s high level by design
2 of 28
137
Pointers are a concept that really doesn't make sense in Python, both because of practical reasons and philisophical reasons. In Python, "variables" are really "lebels" attached to objects, not a specific memory location in your address space. The internals of the Python interpreter do make use of pointers, but that's because it's written in C. Philisophically, the designers of Python view pointers as an intrinsically bad thing - they have all sorts of downsides that would have made Python a bad language. What Python has instead, is bindings - the labels I mentioned above - and they actually do behave in some ways like pointers, but without the downsides. Bindings do not have a type, but the objects they are bound to do have a type, and unlike in C, an object (i.e. a value or more complex type) can have multiple labels. Furthermore, container types like tuples, lists, and dictionaries contain references to objects, which are very like pointers: they don't have a name (binding) but they do give you a way to refer to an object - of any type. If you make a linked list element class in Python like this: class Element: def __init__(self,pred,value): self.pred = pred self.value = value That gives you a linked list with a reference to the previous Element in each object, and you can traverse the links like this: >>> a = Element(None,1) >>> b = Element(a,2) >>> c = Element(b,3) >>> c.pred.pred.value 1 >>> c.pred.value 2 Semantically, that's pretty much like pointers. Generally it's less useful to use such structures in Python, though it's still valid in some situations, but you can take advantage of references to build complex dynamic data structures you can traverse in the same way as most linked-list or tree structures in other languages.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ data-structures-contain-pointers
Data structures contain pointers - Python Morsels
July 18, 2026 - Lists can store pointers that point to anything. This list just happens to point to itself. Just as variables don't contain objects, they just contain pointers to objects, data structures in Python also just store pointers to objects.
๐ŸŒ
Anvil
anvil.works โ€บ articles โ€บ pointers-in-my-python-1
Memory Management in Python - Part 1: What Are Pointers?
So, when you create a list, it will automatically contain pointers if it has any elements. For that reason, weโ€™ll be using a lot of lists as examples throughout this article. ... One Python behaviour that often trips up a lot of beginners ...
๐ŸŒ
SICORPS
sicorps.com โ€บ h0me โ€บ python pointers
Python Pointers -
March 15, 2024 - In traditional programming languages like C and C++, pointers are variables that hold memory addresses of other variables. But in Python, we donโ€™t have traditional pointers! Instead, when you create a list or dictionary in Python, youโ€™re actually creating a pointer to the memory location where those values are stored.
๐ŸŒ
Antonz
antonz.org โ€บ list-internals
How Python list works
November 12, 2021 - The array has a fixed length, but the list should be able to store an arbitrary number of items. We'll tackle them a bit later. The best way to master a data structure is to implement it from scratch. Unfortunately, Python is not well suited for such low-level structures as arrays, because it doesn't support explicit pointers (addresses in memory).
Find elsewhere
๐ŸŒ
Real Python
realpython.com โ€บ pointers-in-python
Pointers in Python: What's the Point? โ€“ Real Python
March 18, 2026 - One way to replicate this type of behavior in Python is by using a mutable type. Consider using a list and modifying the first element: ... Here, add_one(x) accesses the first element and increments its value by one. Using a list means that the end result appears to have modified the value. So pointers in Python do exist?
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how can i use pointer smuggling in python?
r/learnpython on Reddit: How can I use pointer smuggling in Python?
July 19, 2023 -

Just to demonstrate, I wrote the following C code:

#include <stdio.h>

int absolute(int num, int* state)
{
    if(num >= 0)
    {
        *state = 1;
        return num;
    }
    else
    {
        *state = -1;
        return num * (-1);
    }
}
int main() {
    int a, b;
    printf("Enter the number to find its absolute: ");
    scanf("%d", &a);
    int result = absolute(a, &b);
    if(b == -1)
    {
        printf("You entered a negative number");
    }
    else
    {
        printf("You did enter positive number");
    }
    
    printf("The absoluted value is %d", result);

    return 0;
}

In the above C program, I have passed in the value that I want absolute of. As well as a pointer to the variable. In the function, even though I can return the absolute value, I also want to know if the number was infact negative so I have to smuggle that out with the b variable.

Now, I know there are many ways to do it in a better way. But I just made a quick example to demonstrate what I mean.

I know that one can bundle all the stuff to return in a dict or a list and return that out of the function but in my case what if I have to use pointer smuggling?

๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ why you should avoid using python lists?
Python Lists are not good? |Why you should avoid using Python Lists?
October 25, 2024 - To be heterogeneous, each of the elements of the list must contain its own type info, reference count, and all the other information as well. In other words, each item is a complete Python object. So if we break it down further, a Python list contains a pointer, which points to another block of pointers, and within that block, all these pointers in turn point to a separate full Python object like the one we saw earlier.
Top answer
1 of 3
2

I'm not sure exactly what you are trying to do, but you could do something like:

class FooWrapper(object):
    def __init__(self, value):
         self.value = value
    def __repr__(self):
         return 'FooWrapper(' + repr(self.value) + ')'
    def __str__(self):
        return str(self.value)
    def __call__(self,value):
        self.value = value

Here I got rid of your idea of using __repr__ to hide FooWrapper since I think it a bad idea to hide from the programmer what is happening at the REPL. Instead -- I used __str__ so that when you print the object you will print the wrapped value. The __call__ functions as a default method, which doesn't change the meaning of = but is sort of what you want:

>>> vals = [1,2,3]
>>> vals[1] = FooWrapper("Bob")
>>> vals
[1, FooWrapper('Bob'), 3]
>>> for x in vals: print(x)

1
Bob
3
>>> this = vals[1]
>>> this(10)
>>> vals
[1, FooWrapper(10), 3]

However, I think it misleading to refer to this as a pointer. It is just a wrapper object, and is almost certain to make dealing with the wrapped object inconvenient.

On Edit: The following is more of a pointer to a list. It allows you to create something like a pointer object with __call__ used to dereference the pointer (when no argument is passed to it) or to mutate the list (when a value is passed to __call__). It also implements a form of p++ called (pp) with wrap-around (though the wrap-around part could of course be dropped):

class ListPointer(object):
    def __init__(self, myList,i=0):
         self.myList = myList
         self.i = i % len(self.myList)

    def __repr__(self):
         return 'ListPointer(' + repr(self.myList) + ',' + str(self.i) + ')'

    def __str__(self):
        return str(self.myList[self.i])

    def __call__(self,*value):
        if len(value) == 0:
            return self.myList[self.i]
        else:
            self.myList[self.i] = value[0]

    def pp(self):
        self.i = (self.i + 1) % len(self.myList)

Used like this:

>>> vals = ['a','b','c']
>>> this = ListPointer(vals)
>>> this()
'a'
>>> this('d')
>>> vals
['d', 'b', 'c']
>>> this.pp()
>>> this()
'b'
>>> print(this)
b

I think that this is a more transparent way of getting something which acts like a list pointer. It doesn't require the thing pointed to to be wrapped in anything.

2 of 3
0

The __repr__ method can get a string however it wants to. Let's say it says return repr(self.value) + 'here'. If you say this = '4here', what should be affected? Should self.value be assigned to 4 or 4here? What if this had another attribute called key and __repr__ did return repr(self.key) + repr(self.value)? When you did this = '4here', would it assign self.key to the whole string, assign self.value to the whole string, or assign self.key to 4 and self.value to here? What if the string is completely made up by the method? If it says return 'here', what should this = '4here' do?

In short, you can't.

๐ŸŒ
Launch School
launchschool.com โ€บ books โ€บ python โ€บ read โ€บ variables_pointers
How Python objects and variables really work
Instead of copying the object referenced by the variable on the right to the variable on the left, Python only copies the pointer. Thus, when we initialize numbers2 with numbers, we make both numbers and numbers2 point to the same list object: [1, 2, 3]. It's not just the same value but the same list at the same address.
Top answer
1 of 3
2

No, that's not possible. You can't store a reference to a location in a list and try to update it later through assignment.

If you want to implement a work-around, then you might want to use a closure to capture a reference to the desired index in your list. Here's an example:

# Here's my list
mylist = [1, 2, 3, 4]

# Save a reference to the list using a function to close over it
def myref(x): mylist[1] = x

# Update the referenced value to 7
myref(7)

# mylist is now [1, 7, 3, 4]
print mylist

You're stuck using the myref(7) syntax rather than myref = 7 syntax since there's no way to overload the assignment operator in Python, but I think that will work for you.

In your comment on one of the other answers you mentioned that you're actually dealing with an n-dimensional list, and you want to save a reference so that you can update it later when the indices aren't in scope. This works nicely for that case as well. Here's an example:

# My 3D list
list3D = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]

# Find 
def findEntry(data, x):
    for i, page in enumerate(data):
        for j, row in enumerate(page):
            for k, col in enumerate(row):
                if col == x:
                    def myref(y): data[i][j][k] = y
                    return myref

# Get a reference to the first cell containing 4
updater = findEntry(list3D, 4)

# Update that cell to be 44 instead
updater(44)

# list3D is now [[[1, 2], [3, 44]], [[5, 6], [7, 8]]]
print list3D
2 of 3
1

It is better style to use a ref cell, than to use a pointer. Pointers are a distant concept from the point-of-view of python. You can make a cheap ref cell from a list.

pointer = [3]
pointer[0] = 5 #change value of ref cell
pointer[0] #get value of ref cell
๐ŸŒ
Google Groups
groups.google.com โ€บ g โ€บ cython-users โ€บ c โ€บ 3WffkofF6mM
creating a python list of pointers
pointer_list = [] cdef int* foo pointer_list.append(foo) cdef int* retrieved_pointer = pointer_list[0] Is this a sensible thing to do? If so, is it possible? Python lists can only hold pointers to PyObject.
๐ŸŒ
Practicaldatascience
practicaldatascience.org โ€บ notebooks โ€บ class_2 โ€บ week_3 โ€บ 13_objects_and_variables.html
Variables are pointers to objects โ€” Practical Data Science with Python
This is true of lists, numpy arrays, integers, or strings. The name we give it is the variable, and it is a pointer to the place in memory that contains the actual data. So when you create a new array, Python puts that list somewhere in memory, kind of like how you might put something big on a shelf in a warehouse.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 62734758 โ€บ can-you-hold-pointers-in-a-python-list
Can you hold pointers in a python list? - Stack Overflow
c does not have any link to the variable b. ... Python doesn't have pointers. However, pretty much everything has reference semantics. int objects are immutable though ... here c and b are different variables where c is list and b is int so ...
๐ŸŒ
Pencil Programmer
pencilprogrammer.com โ€บ home โ€บ python tutorials โ€บ pointers in python (explained with examples)
Pointers in Python (Explained with Examples) | Pencil Programmer
December 17, 2025 - Types such as list, dictionary, class, and objects, etc in Python behave like pointers under the hood. The assignment operator = in Python automatically creates and assigns a pointer to the variable.