You can loop through a tuple using a for
loop. It’s useful to access all items one by one.
Tuple के सभी items को एक-एक करके access करने के लिए for
loop का इस्तेमाल किया जाता है।
students = ("Abhishek", "Chaitanya", "Naincy", "Shrutika", "Jayati", "Aryan")
for name in students:
print(name)
Output:
Abhishek Chaitanya Naincy Shrutika Jayati Aryan
for i in range(len(students)):
print(i, students[i])
Output:
0 Abhishek 1 Chaitanya 2 Naincy 3 Shrutika 4 Jayati 5 Aryan
for index, name in enumerate(students):
print(index, name)
Output:
0 Abhishek 1 Chaitanya 2 Naincy 3 Shrutika 4 Jayati 5 Aryan
marks = (("Abhishek", 90), ("Naincy", 85), ("Aryan", 88))
for name, score in marks:
print(name, "scored", score)
Output:
Abhishek scored 90 Naincy scored 85 Aryan scored 88