Functions: return sends a value to the caller
def names a reusable procedure. A call gives a parameter its argument value. return ends that call and passes back the result; print displays something but does not return that displayed value.
| Observation | What it means |
|---|---|
| def double(x): return 2*x | procedure definition |
| double(4) | returns 8 |
One worked example
- def add_one(x): return x + 1x is the parameter.
- y = add_one(5)Argument 5 is substituted for x.
- y = 6The result 5 + 1 is assigned to y.
Watch out: Reaching the end of a function or using bare return produces None. print is not a substitute for returning the result.
Goal, prerequisites and card origin
What you will learn: Substitute an argument and use the returned value.
What you need first: Variables and simple expressions.
An original PEAZIT working card. Independent expert review and effectiveness testing have not yet taken place. · v1
Reference for the underlying principle ↗Show connections
def names a reusable procedure. A call gives a parameter its argument value. return ends that call and passes back the result; print displays something but does not return that displayed value.