indexing

In Python, indexing is an operation that allows you to access individual items within a sequence, such as a list, tuple, or string, using integer indices and the syntax sequence[index].

Python uses zero-based indexing, meaning that the first item of a sequence has an index of 0, the second item has an index of 1, and so on. You can also use negative indices to access items from the end of a sequence, with -1 referring to the last item.

Indexing allows you to retrieve specific items from a sequence. In mutable sequences like lists, it also allows you to modify or delete items.

Example

Here’s a quick example of how you can use indexing in a list:

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

>>> # Accessing items by positive index
>>> fruits[0]
'apple'
>>> fruits[1]
'banana'

>>> # Accessing items by negative index
>>> fruits[-1]
'cherry'
>>> fruits[-2]
'banana'

>>> # Modifying and deleting items
>>> fruits[2] = "orange"
>>> fruits
['apple', 'banana', 'orange']
>>> del fruits[0]
>>> fruits
['banana', 'orange']

Tutorial

Python's list Data Type: A Deep Dive With Examples

In this tutorial, you'll dive deep into Python's lists. You'll learn how to create them, update their content, populate and grow them, and more. Along the way, you'll code practical examples that will help you strengthen your skills with this fundamental data type in Python.

intermediate data-structures python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated June 3, 2025