Nearby lessons
65 of 108Python - 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 - bFactorial Example
def fact(num):
result = 1
while num >= 1:
result = result * num
num = num - 1
return resultSummary
| Topic | Meaning |
|---|---|
| return | Sends value back to caller |
| None | Default return value when nothing is returned |
| Multiple values | Returned as a tuple |
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!Python - Recursive Functions