Last modified: March 30, 2020

How to return tuple in python with example

example


def animals():
    #tuple
    animals = ('cat', 'dog', 'zebra', 'shark')
    
    #return
    return animals


#call and print function
print(animals())

output

#('cat', 'dog', 'zebra', 'shark')

loop over tuple


animals = animals()

for animal in animals:
    print(animal)

output

cat                                                                                                                                   
dog                                                                                                                                   
zebra                                                                                                                                 
shark