python / beginner
Snippet
Returning Values from Functions
Functions use the return keyword to send a result back to the part of the program that called the function.
snippet.py
1
2
3
4
5
def add_five(number):return number + 5result = add_five(10)print(result)
Breakdown
1
def add_five(number):
Defines a function that takes one input parameter.
2
return number + 5
Sends the calculated result back to the caller.
3
result = add_five(10)
Calls the function and stores its returned value in a variable.