Default and Keyword Arguments
A parameter can have a default value. Python uses the default when a call leaves out that argument.
def power(number, exponent=2):
return number ** exponent
print(power(4))
print(power(4, exponent=3))
Output:
16
64
power(4) passes only one argument, so exponent uses its default, 2. The result is 4 to the power of 2, which is 16. The second call sets exponent to 3, so the result is 64.
That second call passes an argument by name, as exponent=3. This is called a keyword argument. Naming an argument makes a call easier to read when its meaning would not be clear otherwise.
In the def line, parameters with defaults must come after the parameters without defaults.
In the exercise, add the default greeting. Then change it in the second call with a keyword argument.