
Code
Sensible Defaults
A parameter can have a default value. If the caller leaves that argument out, the default is used.
def brew(potion, doses=1):
return f"{doses} x {potion}"
brew("glow") # '1 x glow'
brew("glow", 3) # '3 x glow'
Parameters with defaults must come after the ones without.
Keyword arguments
You can also pass arguments by name. Then the order doesn't matter, and the call explains itself:
brew(doses=2, potion="calm") # '2 x calm'
Assignment
greet_traveler(name, greeting="Welcome")returns"<greeting>, <name>!": e.g.greet_traveler("Ada")gives"Welcome, Ada!".fuel_for(nights, per_night=3)returnsnights * per_night.
greet_traveler(name, greeting="Welcome")returns"<greeting>, <name>!": e.g.greet_traveler("Ada")gives"Welcome, Ada!".fuel_for(nights, per_night=3)returnsnights * per_night.
main.py Python sleeping
Press Run to try your code, then Check to test it.