Argument Presence Checking via Identity or Boolean Operation?

Peter Otten __peter__ at web.de
Thu Jun 4 05:28:45 EDT 2015


Frank Millman wrote:

> I have a slight variation in that I want to keep a reference to the
> argument -
> 
> def __init__(self, arg=None):
>     self.arg = arg or []
> 
> Based on your comment, I have changed it to -
> 
> def __init__(self, arg=None):
>     self.arg = [] if arg is None else arg
> 
> Does this pass your 'stop and consider' test?

Yes, that avoids the problem of the original code.





More information about the Python-list mailing list