iNTERFACEWARE Products Manual > Learning Center > Learning Python > Functions and Global Variables > Default Parameters |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
When defining a function in Python, you can specify default values for parameters. For example, here is the example from the previous section, modified to supply a default count of 1 if no count is specified:
The output for this code is:
Here, the count parameter has a default value of 1. This is the value that is used if no value is supplied for this parameter, as in the first call to print_HL7_delimiter(). If a value is explicitly specified for the count parameter - as in the second call to print_HL7_delimiter() - the value overrides the default value. If you have more than one parameter for which you have specified a default, and you want to override the default values for some of the parameters but not others, you can provide parameter names as part of the function call. For example:
In the third call to print_with_delimiters(), a value is supplied for the closing_delimiter parameter, overriding the default. The default value of opening_delimiter is left untouched. The output for this code is:
|