Last modified: Jan 10, 2023 By Alexander Williams
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