Account
Categories

Python Tuple Iteration (loop)


Definition

It prints each value of a tuple one by one using a loop.

That means it prints the data of the tuple from left to right one by one using a loop.

Now you will clearly understand the operation through the flowchart.

t = (10, 20, 30)

Loop means: repeat each value one by one

( 10, 20, 30 )
     │
     ▼
   10  ───► print 10
     │
     ▼
   20  ───► print 20
     │
     ▼
   30  ───► print 30

Final Output:
10
20
30

Syntax:

for item in tuple:
    print(item)

Example:

t = (10, 20, 30)

for i in t:
    print(i)

Output:

Note:

print() prints the data on a new line.

Exercise

Create a tuple t = (5, 10, 15) and print each value using a loop.