default mutable arguments
Leif K-Brooks
eurleif at ecritters.biz
Thu Feb 8 14:22:34 EST 2007
Gigs_ wrote:
> I read that this is not the same:
> def functionF(argString="abc", argList = None):
> if argList is None: argList = [] # < this
> ...
> def functionF(argString="abc", argList=None):
> argList = argList or [] # and this
> ...
>
> Why?
If argList is a false value besides None ("", [], {}, False, etc.), the
second example will replace it with an empty list.
More information about the Python-list
mailing list