1.

What is nested tuple? Explain with an example.?

Answer»

In Python, a tuple can be defined inside another tuple; called Nested tuple. In a nested tuple, each tuple is considered as an element. The for loop will be useful to access all the elements in a nested tuple.

Example:

Toppers = ((“Vinodini” , “XII-F”, 98.7), (“Soundarya” , “XII-H” , 97.5),

(“Tharani” , “XII-F”, 95.3), (“Saisri” , “XII-G” , 93.8)) 

for i in Toppers:

print(i)

Output:

(‘Vinodini’ , ‘XII-F’, 98.7)

(‘Soundarya’ , ‘XII-H’ , 97.5)

(‘Tharani’ , ‘XII-F’, 95.3)

(‘Saisri’ , ‘XII-G’ , 93.8)



Discussion

No Comment Found