How to use Loop In Python

Here we are going to form a list of tuples using for loop.

Python3




# create a list of tuples with student
# details
name = [('sravan',7058,98.45),
        ('ojaswi',7059,90.67),
        ('bobby',7060,78.90),
        ('rohith',7081,67.89),
        ('gnanesh',7084,98.01)]
 
# iterate using for loop
for x in name:
   
  # iterate in each tuple element
  for y in x:
      print(y)
       
  print()


Output:

sravan
7058
98.45

ojaswi
7059
90.67

bobby
7060
78.9

rohith
7081
67.89

gnanesh
7084
98.01

How we can iterate through list of tuples in Python

In this article, we will discuss different ways to iterate the list of tuples in Python.

It can be done in these ways:

  • Using Loop.
  • Using enumerate().

Similar Reads

Method 1: Using Loop

Here we are going to form a list of tuples using for loop....

Method 2: Using enumerate()

...