
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to iterate through a tuple in Python?
There are different ways to iterate through a tuple object. The for statement in Python has a variant which traverses a tuple till it is exhausted. It is equivalent to foreach statement in Java. Its syntax is −
for var in tuple: stmt1 stmt2
Example
Following script will print all items in the list
T = (10,20,30,40,50) for var in T: print (T.index(var),var)
Output
The output generated is −
0 10 1 20 2 30 3 40 4 50
Another approach is to iterate over range upto length of tuple, and use it as index of item in tuple
Example
for var in range(len(T)): print (var,T[var])
You can also obtain enumerate object from the tuple and iterate through it.
Output
Following code too gives same output.
for var in enumerate(T): print (var)
- Related Articles
- Iterate through Decade Tuple in Java
- Iterate through Ennead Tuple in Java
- Iterate through Octet Tuple in Java
- Iterate through LabelValue Tuple in Java
- Iterate through KeyValue Tuple in Java
- Iterate through Java Unit Tuple
- Iterate through Java Pair Tuple
- How to iterate through a dictionary in Python?
- How to iterate through a list in Python?
- How to iterate over a C# tuple?
- Python - Ways to iterate tuple list of lists
- How we can iterate through a Python list of tuples?
- How to iterate through Java List?
- How to correctly iterate through getElementsByClassName() in JavaScript?
- How can I iterate through two lists in parallel in Python?

Advertisements