Boolean comparison & PEP8

Grant Edwards grant.b.edwards at gmail.com
Sun Jul 28 21:17:23 EDT 2019


On 2019-07-29, Richard Damon <Richard at Damon-Family.org> wrote:
> On 7/28/19 7:46 PM, Michael Torrie wrote:

>> Yet the recommended solution to the problem of wanting a default
>> argument of an empty list is something like this:
>>
>> def foo(bar=False);
>>     if bar is False:
>>         bar = []
>>
>>     ....
>
> I thought the recommended value was None, not False (so you don't need
> to ask why not True). I suppose if None is a valid value for the input
> you would need something else, and False is one possibility.

Yes 'None' is definitely the normal idiom, and everybody will know
what you're doing.  If you use False, people are going to be confused.

def foo(bar=None)
   if bar is None
       bar = []
   ...







More information about the Python-list mailing list