The short answer to this is that, Python is a pass-by-object-reference language, not pass-by-reference as implied in the question. It means that:

  1. result and result_tail are two variables that happen to point at the same value
  2. Mutation / Changing of the underlying value (result_tail.next = ListNode(1)) will affect the value shown by result
  3. However, assigning / pointing the variable result_tail to another value will NOT affect the value of result
  4. result_tail = result_tail.next is assigning the next node of the node that is currently assigned by the variable

The following is an visualization of the values that are assigned to the variables (r = result, rt = result_tail):

result = ListNode(0)
#r
#0 -> None

result_tail = result
#r
#0 -> None
#rt

result_tail.next = ListNode(1)
#r
#0 -> 1 -> None
#rt

result_tail = result_tail.next
#r
#0 -> 1 -> None
#     rt

result_tail.next = ListNode(2)
#r
#0 -> 1 -> 2 -> None
#     rt

result_tail = result_tail.next
#r
#0 -> 1 -> 2 -> None
#          rt

References for additional reading:

  • An article explaining the Python pass-by-object reference style in detail https://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/
  • An answer explaining Python's pass-by-object reference style https://stackoverflow.com/a/33066581/12295149
  • Question asking on Python's object reference style Understanding Python's call-by-object style of passing function arguments
Answer from Joseph on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-linked-list
Python Linked List - GeeksforGeeks
December 11, 2025 - Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-nameerror-name-listnode-is-not-defined
How To Fix Nameerror: Name 'Listnode' Is Not Defined - GeeksforGeeks
July 23, 2025 - NameError is a runtime error that ... 'Listnode' is not defined," it suggests that the interpreter cannot find a definition for the identifier 'Listnode' in the current context....
🌐
GeeksforGeeks
geeksforgeeks.org › python-program-for-inserting-a-node-in-a-linked-list
Python Program For Inserting A Node In A Linked List - GeeksforGeeks
September 5, 2022 - # A complete working Python program to demonstrate all # insertion methods of linked list # Node class class Node: # Function to initialize the # node object def __init__(self, data): # Assign data self.data = data # Initialize next as null self.next = None # Linked List class contains a # Node object class LinkedList: # Function to initialize head def __init__(self): self.head = None # Functio to insert a new node at # the beginning def push(self, new_data): # 1 & 2: Allocate the Node & # Put in the data new_node = Node(new_data) # 3.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › singly-linked-list-tutorial
Singly Linked List Tutorial - GeeksforGeeks
January 13, 2026 - Python · # Definition of a Node in a singly linked list class Node: def __init__(self, data): # Data part of the node self.data = data self.next = None ·
🌐
TutorialsPoint
tutorialspoint.com › python_data_structure › python_linked_lists.htm
Python - Linked Lists
A linked list is a sequence of data elements, which are connected together via links. Each data element contains a connection to another data element in form of a pointer. Python does not have linked lists in its standard library.
🌐
GeeksforGeeks
geeksforgeeks.org › python › singly-linked-list-in-python
Singly Linked List in Python - GeeksforGeeks
July 23, 2025 - To traverse a singly linked list in Python, you simply need to iterate through each node starting from the head node and print the data of each node until you reach the end of the list (i.e.
Top answer
1 of 4
27

The short answer to this is that, Python is a pass-by-object-reference language, not pass-by-reference as implied in the question. It means that:

  1. result and result_tail are two variables that happen to point at the same value
  2. Mutation / Changing of the underlying value (result_tail.next = ListNode(1)) will affect the value shown by result
  3. However, assigning / pointing the variable result_tail to another value will NOT affect the value of result
  4. result_tail = result_tail.next is assigning the next node of the node that is currently assigned by the variable

The following is an visualization of the values that are assigned to the variables (r = result, rt = result_tail):

result = ListNode(0)
#r
#0 -> None

result_tail = result
#r
#0 -> None
#rt

result_tail.next = ListNode(1)
#r
#0 -> 1 -> None
#rt

result_tail = result_tail.next
#r
#0 -> 1 -> None
#     rt

result_tail.next = ListNode(2)
#r
#0 -> 1 -> 2 -> None
#     rt

result_tail = result_tail.next
#r
#0 -> 1 -> 2 -> None
#          rt

References for additional reading:

  • An article explaining the Python pass-by-object reference style in detail https://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/
  • An answer explaining Python's pass-by-object reference style https://stackoverflow.com/a/33066581/12295149
  • Question asking on Python's object reference style Understanding Python's call-by-object style of passing function arguments
2 of 4
16

For those reading this in the future: I wanted to debug linked list problems on a local environment so here is what I did.

  1. Modified the Leetcode code for ListNode by including the dunder "repr" method. This is for when you want to print a ListNode to see what its value and next node(s).
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

    def __repr__(self):
        return "ListNode(val=" + str(self.val) + ", next={" + str(self.next) + "})"
  1. Next, I made a recursive function that makes a nested ListNode when you pass in a list. This is so you can test your methods by passing in lists (instead of having to manually make a confusing looking ListNode yourself.
def list_to_LL(arr):
    if len(arr) < 1:
        return None

    if len(arr) == 1:
        return ListNode(arr[0])
    return ListNode(arr[0], next=list_to_LL(arr[1:]))
  1. Here is an example that tests my answer for the "reverseList" problem:
def reverseList(head: ListNode) -> ListNode:
    prev = None
    while head:
        next_node = head.next
        head.next = prev
        prev = head
        head = next_node

    return prev


# test cases
t1 = list_to_LL([1, 2, 3, 4, 5])  #ListNode(val=1, next={ListNode(val=2, next={ListNode(val=3, next={ListNode(val=4, next={ListNode(val=5, next={None})})})})})
t2 = list_to_LL([1, 2])  #ListNode(val=1, next={ListNode(val=2, next={None})})
t3 = list_to_LL([])

# answers
print(reverseList(t1))
print(reverseList(t2))
print(reverseList(t3))
Find elsewhere
🌐
CodeRivers
coderivers.org › blog › listnode-python
Understanding and Using ListNode in Python - CodeRivers
July 21, 2026 - Whether you are implementing a simple singly linked list, solving coding interview problems on LeetCode, or building a more complex doubly linked list, the knowledge of ListNode will serve as a solid foundation. By following best practices — using type hints, understanding time complexity trade-offs, and choosing the right data structure for your workload — you can write linked list code that is both correct and performant. ... Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein (CLRS) GeeksforGeeks — Time and Space Complexity of Linked List
🌐
Scribd
scribd.com › document › 422676003 › Reverse-a-Linked-List-GeeksforGeeks
Reverse A Linked List - GeeksforGeeks | Download Free PDF
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Stack Abuse
stackabuse.com › python-linked-lists
Python Linked Lists
August 25, 2023 - To have a data structure we can work with, we define a node. We'll implement a node as a class named ListNode. The class contains the definition to create an object instance, in this case, with two variables - data to keep the node value, and next to store the reference to the next node in the list.
🌐
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › what is a list node in python? (2 examples)
What is a List Node in Python? (2 Examples) | Linked List Structure
May 15, 2023 - class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next # instantiate the nodes node1 = ListNode(1) node2 = ListNode(2) node3 = ListNode(3) node4 = ListNode(4) # link the nodes node1.next = node2 node2.next = node3 node3.next = node4 # traverse the linked list and print each node's value current_node = node1 while current_node is not None: print(current_node.val) current_node = current_node.next # 1 # 2 # 3 # 4 · In the above example, we first created a Python class called “ListNode” with a val attribute to store the node’s value, and a next attribute to store a reference to the next node in the list.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-library-for-linked-list
Python Library for Linked List - GeeksforGeeks
July 15, 2025 - To start with Python, it does not have a linked list library built into it like the classical programming languages. Python does have an inbuilt type list that works as a dynamic array but its operation shouldn't be confused with a typical function ...
🌐
CodeSignal
codesignal.com › learn › courses › getting-deep-into-complex-algorithms-for-interviews-with-python › lessons › linked-list-operations-in-python
Linked List Operations in Python
class ListNode: def __init__(self, value=0, next=None): self.value = value # Holds the value or data of the node self.next = next # Points to the next node in the linked list; default is None # Initialization of linked list head = ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(5)))))
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › types-of-linked-list
Types of Linked List - GeeksforGeeks
July 15, 2025 - # Python program to illustrate creation # and traversal of Singly Linked List class Node: def __init__(self, data): self.data = data self.next = None def print_list(node): # Iterate till node reaches None while node is not None: # Print the data print(node.data, end=" ") node = node.next if __name__ == "__main__": #Linked List 1 -> 2 -> 3 head = Node(1) second = Node(2) third = Node(3) head.next = second second.next = third print_list(head)
🌐
GitHub
gist.github.com › Jay87682 › 3935ac67616875e043d590c0b8b19f6d
python listnode · GitHub
python listnode · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
Real Python
realpython.com › linked-lists-python
Linked Lists in Python: An Introduction – Real Python
June 24, 2026 - In this article, you'll learn what linked lists are and when to use them, such as when you want to implement queues, stacks, or graphs. You'll also learn how to use collections.deque to improve the performance of your linked lists and how to implement linked lists in your own projects.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-for-finding-length-of-a-linked-list-iterative-and-recursive-approach
Python Program For Finding Length Of A Linked List - GeeksforGeeks
July 23, 2025 - # Python program for the above approach # Linked List Node Class class Node: def __init__(self, data=None): self.data = data self.next = None # Linked List Class class LinkedList: def __init__(self): self.head = None # Function to insert into Linked List def insert(self, data): new_node = Node(data) if self.head is None: self.head = new_node else: current_node = self.head while current_node.next: current_node = current_node.next current_node.next = new_node # Function to find the length of # the Linked List def length(self): visited_nodes = {} current_node = self.head while current_node: if current_node in visited_nodes: break visited_nodes[current_node] = True current_node = current_node.next return len(visited_nodes) # Driver Code linked_list = LinkedList() linked_list.insert(1) linked_list.insert(2) linked_list.insert(3) # Function Call print(linked_list.length())
🌐
CSCI 0112
cs0112.github.io › Lectures › lecture19.html
Linked Lists (Part 1) | CSCI 0112 - Fall 2024
October 21, 2024 - Let’s make some classes that let us turn this into something we can write in Python. The picture above is a hint: we should probably have a kind of object to represent those links. class ListNode: def __init__(self, data): self.data = data self.next = None
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › linked-list-data-structure
Linked List Data Structure - GeeksforGeeks
DSA Python · Last Updated : 12 Aug, 2026 · A linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays.
Published: August 12, 2026
🌐
Reddit
reddit.com › r/learnpython › help me out with listnode
r/learnpython on Reddit: Help me out with ListNode
July 10, 2025 -

Hello all, I completed my 12th this may( high school graduate ) going to attend Engineering classes from next month. So I decided to start LeetCode question. Till now I have completed about 13 questions which includes 9 easy ones, 3 medium ones and 1 hard question( in python language ) with whatever was thought to me in my school, but recently I see many questions in from ***ListNode***, but searching in youtube doesn't shows anything about ListNode but only about Linked list. So kindly suggest me or provide the resources to learn more about it.

Thank you!