Default function argument [Python]

def kill_by_priority(e_types=None, melee_types_to_ignore=None, radius=9999):
    RANGE_TYPES = ['shaman', 'thrower', 'fangrider', 'archer']
    DEFAULT_PRIORITY = RANGE_TYPES + ['ogre', 'scout', 'munchkin']
    e_types = e_types or DEFAULT_PRIORITY

The first call of say throws an exception “Say what?” like for non-declared variable.

Without the say calls python “or trick” just doesn’t work - default value is always returned by the expression even if truthy argument was passed.

I tried explicit if and removing =None after argument name. That doesn’t work.

Has anyone a workaround for the case?


I think you have to define a new variable that is equivalent to the input, e.g eTypes = e_types.


eTypes is not pythonic, used arg_e_types. :smile:

Actually, thanks. That did the trick.