Python Programming Language: How to Loop Through Tuples

Jesse L
2 min readJun 29, 2022

Hi everyone, welcome back. In these examples, we will be going over how to loop through Tuples in Python. Tuples can be used to store a collection of data. A Tuple in Python is immutable and can allow duplicate values. The elements within a Tuple are indexed and ordered. With this introduction out of the way, let’s get into it.

Creating Tuple

Let’s start by creating our Tuple:

myTuple = (1, 2, 3)
print(myTuple)
Output:
(1, 2, 3)

So now, we have created a Tuple with a few elements. We can verify that it was successfully created by printing the Tuple and checking the output. Now, let’s see how we can loop through the Tuple.

While Loop

Let’s try to use a while loop to iterate through the Tuple and print each element individually. Let’s see an example:

myTuple = (1, 2, 3)

i = 0
while i < len(myTuple):
print(myTuple[i])
i = i + 1
Output:
1
2
3

As we can see in the example above, we used a while loop to iterate through the Tuple. With each iteration, we printed the corresponding element to verify that we are successfully iterating through each element individually.

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet