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.
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.
tuple_1 = (2, 4, 6) print(tuple_1) print(tuple_1) print(tuple_1)Try Online
2 4 6
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.
tuple_1 = (2, 4, 6) for item in tuple_1: print(item)Try Online
2 4 6
In this Python Tutorial, we learned how to access values of items in a tuple in Python.