Sunday, 20 December 2020

Python: Iterate over elements of a tuple

Using ‘for’ loop, you can iterate over the elements of a tuple.

 

tuple_iteration.py

emp1 = (1, "Krishna", "Gurram")

for elem in emp1:
   print(elem)

 

Output

$python3 tuple_iteration.py 
1
Krishna
Gurram

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment