Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How can we return a list from a Python function?

I have a list given below as follows

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

How do I return this list or any given list from a python function?


1 Answer
Manogna

There are so many ways we can return a list from a python function. One such function is given below.

def retList():
    list = []
    for i in range(0,10):
        list.append(i)
    return list
a = retList()
print a

OUTPUT

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

 

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.