Python function return list of values | Example code

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):
    return list1


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


Python function return list

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

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.