Functions are written to perform tasks and sometimes, we may need the outcome of the tasks, this can be done via return
.
To return something from a function we add the return
keyword followed by the value to return, like here with return label
.
def age_label(age):
label = "User age: " + age
return label
A function can return any type of value, like a string, integer, float, or boolean. We call this value the function's "output".
In the example below, we want the function to output the result
of the number
parameter multiplied by 10.
def times_ten(number):
result = number * 10
return result
We can use the return value of a function like any value by calling the function. Here, we call age_label("22")
to use its value.
def age_label(age):
label = "User age: " + age
return label
print(age_label("22"))