Access Items of a Tuple

A Python Tuple is an ordered collection of items and also an iterable. Therefore, we can read values of items using index, or iterate over items using for loop or while loop.

In this tutorial, we will learn how to read items of a tuple using index or iterate over the items using a looping technique.

Examples

1. Access Items of a Tuple using Index

In the following program, we create a tuple with three items, and print items one at a time by accessing them using index.

Python Program

</>
Copy
tuple_1 = (2, 4, 6)
print(tuple_1[0])
print(tuple_1[1])
print(tuple_1[2])

Output

2
4
6

2. Access Items of Tuple using For Loop

Since tuple is an iterable object, we could use for loop to iterate over the items of tuple, and access their values.

Python Program

</>
Copy
tuple_1 = (2, 4, 6)

for item in tuple_1:
    print(item)

Output

2
4
6

Conclusion

In this Python Tutorial, we learned how to access values of items in a tuple in Python.