Parameters & Return

Return Values

Functions can return values using the return statement. This lets you use the result of a function in other parts of your code.
python
def add(a, b):
    return a + b

result = add(5, 3)
print(result)  # 8
print(add(10, 20))  # 30

Default Parameters

You can give parameters default values. If the caller doesn't provide a value, the default is used.
python
def greet(name, greeting="Hello"):
    return f"{greeting}, {name}!"

print(greet("Alice"))           # Hello, Alice!
print(greet("Bob", "Hey"))      # Hey, Bob!

Multiple Return Values

Python functions can return multiple values as a tuple, which you can unpack into separate variables.
python
def min_max(numbers):
    return min(numbers), max(numbers)

lowest, highest = min_max([3, 1, 4, 1, 5, 9])
print(f"Min: {lowest}, Max: {highest}")

Tip:A function without a return statement returns None by default.

PlaygroundPython
Output
Click "Run" to see output

💬 Got questions? Ask me anything!