Skip to content
dreamcode
dreamcode
Map
Default & keyword args
Lesson 23 of 77
+15 XP on finish
PYTHON BASICSChapter 4 · Functions

Defaults and keywords

You can give parameters default values. If the caller leaves them out, Python uses the default. You can also pass arguments by keyword (by name) instead of position.

Worked example

How it reads

  • color="neon" sets a default value for color
  • glow(brightness=10) specifies brightness by name, while color defaults to "neon"
  • str(brightness) converts the integer to text so we can add it to other text
Cloud tip: All parameters with default values must come after parameters without default values.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Add a second parameter mood with the default "calm", so set_sky() prints The sky is pink and calm, then call set_sky(mood="wild") to print The sky is pink and wild.

Press Run to check your work.