Paul's Python CoursePPC

Keyword arguments

Not met yet

A call can name its arguments: tag("clock", fragile=True). Named, or keyword, arguments go to the parameter with that name, in any order, and let you skip the defaults you're happy with. Unnamed, positional arguments fill the parameters from the left, and always come first.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks a keyword argument fills the next parameter in order, whatever its name.
  • Thinks you cannot skip a parameter that has a default in order to name a later one.
  • Thinks positional arguments skip over parameters that have defaults.
  • Thinks keyword arguments must be given in the same order as the parameters.
  • Thinks a keyword argument can replace a value already given to the same parameter by position.

Where it comes up