Open In App

Python Linked List

Last Updated : 19 Sep, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A linked list is a type of linear data structure similar to arrays. It is a collection of nodes that are linked with each other. A node contains two things first is data and second is a link that connects it with another node. Below is an example of a linked list with four nodes and each node contains character data and a link to another node. Our first node is where head points and we can access all the elements of the linked list using the head.

Linked-list

Creating a Node Class

We have created a Node class in which we have defined a __init__ function to initialize the node with the data passed as an argument and a reference with None because if we have only one node then there is nothing in its reference.

Python
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None

Implementation of Simple Linked List

Example: Below is a simple example to create a singly linked list with three nodes containing integer data.

Python
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None

# Create nodes
node1 = Node(15)
node2 = Node(3)
node3 = Node(17)
node4 = Node(90)

# Link nodes
node1.next = node2
node2.next = node3
node3.next = node4  

head = node1  # Head points to the first node

# Traverse and print the linked list
current = head
while current:
    print(current.data, end=" -> ")
    current = current.next
print("None")

Output
15 -> 3 -> 17 -> 90 -> None

Basics

Linked lists come in different forms depending on how nodes are connected. Each type has its own advantages and is used based on problem requirements. The main types of linked lists are:

To practice problems related to linked list, refer to this article Linked List Data Structure


Article Tags :

Explore