Looking for python Answers? Try Ask4KnowledgeBase
Looking for python Keywords? Try Ask4Keywords

Python Language Defining a function with optional arguments


Optional arguments can be defined by assigning (using =) a default value to the argument-name:

def make(action='nothing'):
    return action

Calling this function is possible in 3 different ways:

# Out: fun

# Out: sleep

# The argument is optional so the function will use the default value if the argument is 
# not passed in.
# Out: nothing


Mutable types (list, dict, set, etc.) should be treated with care when given as default attribute. Any mutation of the default argument will change it permanently. See Defining a function with optional mutable arguments.