Computer >> Computer tutorials >  >> Programming >> Python

How can we return a list from a Python function?


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

Example

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]