Python Tutoring Online
 Home            

Access Python List Items

Accessing Python list items means retrieving individual elements from a list using their position, or index. Python lists use zero-based indexing, which means the first item has index 0, the second item has index 1, and so on.

Python also supports negative indexing, which allows you to access items from the end of a list. When you need to retrieve multiple items, Python provides list slicing.

Understanding how to access list elements is one of the most important skills when learning Python because lists are commonly used to store names, numbers, scores, products, records and other collections of data.

Need Help Learning Python?

If Python list indexing is difficult to understand, one-to-one Python tutoring can help you learn indexing, slicing and other Python programming concepts through practical examples.

Get help with Python programming, assignments, projects, coding exercises and debugging.

Get Python Tutoring Help

Python List Indexing

Each element in a Python list has a position called an index. Python starts counting list indexes from 0.

Consider this list:

Python
colors = ["Red", "Orange", "Yellow", "Green", "Blue"]

The elements and their indexes are:

Index List Item
0 Red
1 Orange
2 Yellow
3 Green
4 Blue

An index is placed inside square brackets after the list name to access the corresponding item.

Access Python List Items Using Positive Indexes

Positive indexes count from the beginning of the list. The first element has index 0.

Python
colors = ["Red", "Orange", "Yellow", "Green", "Blue"]

print(colors[0])
print(colors[2])
print(colors[4])

Output


Red
Yellow
Blue

In this example, colors[0] accesses the first item, colors[2] accesses the third item and colors[4] accesses the fifth item.

Access the First List Item

Because Python uses zero-based indexing, the first item is always accessed using index 0.

Python
fruits = ["Apple", "Banana", "Orange"]

print(fruits[0])

Output


Apple

Access the Last List Item

The last item can be accessed using its positive index if the length of the list is known. However, Python's negative indexing provides a simpler way to access the last item.

Python
fruits = ["Apple", "Banana", "Orange"]

print(fruits[-1])

Output


Orange

Using -1 to access the last element is one of the most useful Python list indexing techniques.

Access Python List Items Using Negative Indexes

Negative indexes count from the end of a list. The last element has index -1, the second-last element has index -2, and so on.

Positive Index Negative Index Value
0 -5 Red
1 -4 Orange
2 -3 Yellow
3 -2 Green
4 -1 Blue

For example:

Python
colors = ["Red", "Orange", "Yellow", "Green", "Blue"]

print(colors[-1])
print(colors[-2])
print(colors[-3])

Output


Blue
Green
Yellow

Access a List Item Using a Variable

The index used to access a list item can be stored in a variable. This is useful when the required position is determined dynamically by a program.

Python
fruits = ["Apple", "Banana", "Orange", "Mango"]

index = 2

print(fruits[index])

Output


Orange

The variable index contains the value 2, so Python accesses the element at index 2.

Access List Items Using len()

The built-in len() function returns the number of items in a list.

Python
fruits = ["Apple", "Banana", "Orange", "Mango"]

print(len(fruits))

Output


4

Because list indexes start at zero, the last positive index is always one less than the length of the list.

Python
fruits = ["Apple", "Banana", "Orange", "Mango"]

last_index = len(fruits) - 1

print(fruits[last_index])

Output


Mango

Access Multiple List Items

Indexing is normally used to retrieve one list item. When you need several items at once, Python provides list slicing.

The basic syntax is:


list[start:stop]

The start position is included, while the stop position is excluded.

Python
numbers = [10, 20, 30, 40, 50]

print(numbers[1:4])

Output


[20, 30, 40]

This page focuses on accessing list items. For the complete treatment of slicing syntax, step values, negative slicing and advanced slicing techniques, see the List Slicing tutorial in the sidebar.

Access the First Few List Items

A slice can be used when you want to access the first several elements of a list.

Python
numbers = [10, 20, 30, 40, 50]

print(numbers[:3])

Output


[10, 20, 30]

Access the Last Few List Items

Negative indexes can also be combined with slicing when you need the last few elements of a list.

Python
numbers = [10, 20, 30, 40, 50]

print(numbers[-3:])

Output


[30, 40, 50]

More advanced slicing techniques are covered separately in the List Slicing tutorial.

Check if an Item Exists in a List

Sometimes you need to determine whether a particular value is present in a list rather than retrieve it using an index.

Python provides the in operator for this purpose.

Python
fruits = ["apple", "banana", "cherry"]

if "apple" in fruits:
    print("Apple is in the list")

Output


Apple is in the list

Check if an Item Does Not Exist

The not in operator checks whether a value is not present in a list.

Python
fruits = ["apple", "banana", "cherry"]

if "orange" not in fruits:
    print("Orange is not in the list")

Output


Orange is not in the list

Access Items from a Nested List

A nested list contains another list as one or more of its elements. Accessing an item inside a nested list requires multiple indexes.

Python
students = [
    ["Ali", 18],
    ["Sara", 19],
    ["John", 20]
]

print(students[0][0])
print(students[1][1])

Output


Ali
19

In students[0][0], the first index selects the first inner list and the second index selects an item from that inner list.

For more detailed techniques involving nested lists, see the Nested Lists tutorial in the sidebar.

Access Items from a List with Different Data Types

A Python list can contain different types of values. Individual elements can still be accessed using their indexes.

Python
data = [25, "Python", 3.14, True]

print(data[0])
print(data[1])
print(data[2])
print(data[3])

Output


25
Python
3.14
True

Common Errors When Accessing Python List Items

IndexError

An IndexError occurs when you attempt to access an index that does not exist.

Python
numbers = [10, 20, 30]

print(numbers[3])

The list contains three elements, so its valid positive indexes are 0, 1 and 2. Index 3 does not exist.

Using a Non-Integer Index

List indexes normally need to be integers. Using a string as an index causes a TypeError.

Python
numbers = [10, 20, 30]

print(numbers["one"])

Use an integer index such as numbers[0] or a variable containing an integer.

Confusing an Index with a List Value

An index represents a position, not the value stored at that position.

Python
numbers = [10, 20, 30]

print(numbers[1])

Output


20

The expression numbers[1] accesses the item at position 1. It does not search for the value 1.

Forgetting Zero-Based Indexing

Remember that the first list item has index 0.

Python
fruits = ["Apple", "Banana", "Orange"]

print(fruits[0])

Output


Apple

Practical Examples of Accessing List Items

Access a Student Score

Python
scores = [78, 85, 92, 88, 74]

print(scores[2])

Output


92

Access the Most Recent Value

Negative indexing is useful when the most recent value is stored at the end of a list.

Python
temperatures = [31, 32, 30, 33, 35]

print(temperatures[-1])

Output


35

Check Whether a Product Exists

Python
products = ["Laptop", "Mouse", "Keyboard", "Monitor"]

if "Mouse" in products:
    print("Product available")

Output


Product available

Access the First Three Values

Python
sales = [1200, 1500, 1800, 2100, 2400]

print(sales[:3])

Output


[1200, 1500, 1800]

Python List Access: Key Points to Remember

Conclusion

Accessing list elements is a fundamental Python skill. Individual items can be retrieved using positive or negative indexes, while slicing allows you to access a range of elements.

Python also provides the in and not in operators for checking whether values are present in a list. Understanding these techniques makes it easier to work with lists in programming exercises and real-world applications.

Once you understand how to access Python list items, you can move on to modifying list contents, adding new elements, removing elements and processing lists with loops.

Need Help with Python List Indexing?

Get practical one-to-one help with Python lists, indexing, slicing, programming exercises, assignments and projects.

Get Python Tutoring Help




Stuck Learning Python?

Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.

Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.

    Get Python Tutoring

PythonTutor.net

Home    Tutorial     Online Live Trainings    Contact Us           © 2026 All rights reserved by www.PythonTutor.net