Skip to content

Python function return list of values | Example code

  • by

It is very easy to code in Python to return list data from functions. A list that contains multiple values, so the function will return multiple values.

Example function return list in Python

Simple example code.

Look at the function below. It returns a list that contains ten numbers.

def ret_list():
    list1 = []
    for i in range(0, 10):
        list1.append(i)
    return list1


print(ret_list())

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

Another example: This function returns a list

A returning value in the list contains strings and numbers.

def fun():
    str1 = "Hello"
    x = 100
    return [str1, x]


# Driver code
print(fun())

Output:

Python function return list

Do comment if you have any questions or suggestions on this python function return topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading