Paul's Python CoursePPC

Default arguments

Not met yet

A parameter can have a default: def label(item, copies=1):. When a call leaves that argument out, the function uses the default; when the call passes one, the default is ignored. Parameters with defaults go after the ones without.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks a parameter with a default must still be passed in every call.
  • Thinks a left-out argument becomes None rather than the default in the def line.
  • Thinks the default is used even when the call passes a value.

Where it comes up