No, function keyword parameter defaults are determined when the function is defined, not when the function is executed.
Set the default to None
and detect that:
def perms(elements, setLength=None):
if setLength is None:
setLength = elements
If you need to be able to specify None
as a argument, use a different sentinel value:
_sentinel = object()
def perms(elements, setLength=_sentinel):
if setLength is _sentinel:
setLength = elements
Now callers can set setLength
to None
and it won’t be seen as the default.