logo
  • Home
  • About
  • Contact Us

How to return tuple in python with example

  • Said Py
  • March 30, 2020

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

Related posts

2 Methods to create an empty tuple in python

turn a List to a Tuple in python

get the last element of tuple in python

Search

    Categories

    • Django Snippet
    • Django Tutorial
    • Python
    • Python Libraries
    • Python Tutorial
    • Questions And Answers

    Recent Posts

    Python-Pillow: How to Show an image in Python

    May 08, 2022

    Python-Pillow: How to get Image Filename, Size, Format, and Mode

    May 05, 2022

    Pillow: Installation and getting started (Python)

    April 29, 2022

    How to insert .format multiple variables in Python

    April 27, 2022

    How to put variable in regex pattern in Python

    April 20, 2022

    How to use Django JsonResponse with example

    April 16, 2022

    Tags

    • python
    • pillow
    • variable
    • django
    • http
    • string
    • loop
    • tuple
    • list
    • BeautifulSoup

    Our Links

    • Home
    • About us
    • Privacy policy

    Our Works

    • Tutorials
    • Examples
    • Snippets
    • Solutions

    Social Media

    About Pytutorial

    Python and Django Tutorials Blog