Skip to content

Python function return variable

  • by

You can return variables from Python functions the same as return any value. You have to make sure variables are in the scope of the function.

Note: Python function is not required to return a variable, it can return zero, one, two, or more variables.

Python function return variable

Simple example code store a return value in a variable in Python.

# int var
def func():
    a = 10
    return a


# string var
def func2():
    x = "random"

    return x



Python function return variable


def myfunction():
    value = "myvalue"
    return value

var = myfunction()

Output: myvalue

Do comment if you have any doubts or suggestions on this Python function 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