Nearby lessons

65 of 108

Python - Return Statement

What Is return?

The return statement sends a value back from a function to the caller.

It is used when a function needs to produce a result.

Simple Example

def add(x, y):
    return x + y

result = add(10, 20)
print(result)

Default Return Value

If a function does not use return, Python returns None.

def f1():
    print("Hello")

print(f1())

Returning Multiple Values

Python can return more than one value from a function.

def sum_sub(a, b):
    return a + b, a - b

Factorial Example

def fact(num):
    result = 1
    while num >= 1:
        result = result * num
        num = num - 1
    return result

Summary

Topic Meaning
returnSends value back to caller
NoneDefault return value when nothing is returned
Multiple valuesReturned as a tuple

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!Python - Recursive Functions