Access List Items

3 min read ·

Accessing list items is a core concept in Python. Because lists are ordered, every item has a fixed position (index) that can be used to read data efficiently.
This topic covers basic to advanced ways of accessing list elements.

List Indexing Basics

List items are accessed using index numbers. Indexing in Python starts from 0.

Negative Indexing

Negative indexing allows access from the end of the list.
IndexMeaning
-1Last item
-2Second last item

Accessing a Range of Items (Slicing)

Slicing allows you to access multiple items at once.

Syntax

  • start is inclusive
  • end is exclusive

Slicing with Negative Indexes


Accessing with Step Value

You can control how many items to skip using step.

Syntax


Accessing List Items Using Loop

Using for Loop


Using Index with range()


Accessing Nested List Items

Lists can contain other lists (nested lists).

Accessing List Items Using Conditions


Accessing Items with Unpacking

You can unpack list values into variables.

Extended Unpacking


Index Out of Range Error (Important)

Accessing an index that does not exist raises an error.
Error:

Safe Way to Access


Common Mistakes

Assuming Index Starts from 1


Confusing Slicing End Index