Access Tuple Items
3 min read ·
Accessing tuple items in Python is very similar to lists, because tuples are ordered collections.
The key difference is that tuples are read-only, meaning you can access items but cannot modify them.
This topic covers all ways to access tuple elements, from basic indexing to advanced unpacking.
Access Tuple Items Using Indexing
Tuple items are indexed starting from
0.Negative Indexing
Negative indexing allows access from the end of the tuple.
| Index | Meaning |
|---|---|
-1 | Last item |
-2 | Second last item |
Access a Range of Tuple Items (Slicing)
Slicing returns a new tuple.
Syntax
Slicing with Negative Indexes
Slicing with Step Value
Access Tuple Items Using Loop
Using for Loop
Using Index Loop
Access Nested Tuple Items
Tuples can contain other tuples.
Check If Item Exists
Access Using Tuple Unpacking
Unpacking assigns tuple values to variables.
Extended Unpacking
Access Returned Tuple from Function
Index Out of Range Error
Raises: