Parameters and Return Values
A parameter is a name that receives an input when a function is called.
value is a parameter. It refers to whatever argument is passed during the
call:
Output:
8
14
Arguments and Parameters
In this call:
double(4)
4 is the argument.
In this definition:
def double(value):
value is the parameter.
The argument supplies a value. The parameter is the local name that receives it.
return Sends a Value Back
This function returns a value:
The caller can print it:
print(add(2, 3))
or store it:
print Is Not return
This function prints a value but returns None:
This function returns a value:
The distinction matters. A returned value can be used by later code.
print versus return
The first function only prints. The second returns a value that can be reused.
Ready to run.
Printing Is Not Returning
Expecting a printed value to be reusable:
The second print shows None, because show_total() did not return a value.
What value does this function call return?
Compute it first, then check your number.
HintBind arguments to parameters
In this call, weight receives 3 and value receives 4.
SolutionThe function returns twelve
Substitute the arguments into weight * value: 3 * 4 is 12, so the call
returns 12.
Parameters Enter and Return Values Leave
Parameters receive inputs. return sends a value back. Prefer returning values
when later code needs to use the result.