Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FUNCTIONS / CHAPTER 04 / Learn / LESSON 02
Second class. You can pass an argument by name: label(name="weight", unit="kg"). That is a keyword argument — order is no longer the only way.
A parameter can have a default value:
def label(name, unit="kg"):
return f"{name} {unit}"Then label("weight") uses "kg", and label("height", unit="m") overrides it.
Rule: parameters with defaults come after those without. Common mistake: mixing positional and keyword carelessly, or expecting a mutable default to “remember” between calls (today we only use simple string/number defaults).
Learn: default value and keyword call.
PROFILE IDLE
›