Boolean comparison & PEP8
Chris Angelico
rosuav at gmail.com
Sun Jul 28 20:46:10 EDT 2019
On Mon, Jul 29, 2019 at 10:43 AM Richard Damon <Richard at damon-family.org> wrote:
>
> On 7/28/19 8:25 PM, Chris Angelico wrote:
> > Of course, if the third value can be simplified away (eg None means
> > "use the global default"), then you can still just use "if verbose is
> > None:" and then reassign it. But this is a legit reason to use "is
> > False".
> >
> > ChrisA
>
> The more common way to handle the 3 value case in my experience is to
> first handle the 'special case' (check for None in your example) and
> then use the normal truthiness test.
>
That works fine if you can actually handle the special case first and
dispose of it, but that doesn't always work, and when it doesn't, you
may indeed want to specify "is False" or "is True".
Chris
More information about the Python-list
mailing list