Comparisons and singletons

David Isaac aisaac0 at verizon.net
Sun Mar 26 11:32:31 CEST 2006


Alan asked:
> > 2. If I really want a value True will I ever go astray with the test:
> > if a is True:
> > >>> a = True
> > >>> b = 1.
> > >>> c = 1
> > >>> a is True, b is True, c is True
> > (True, False, False)

"Ziga Seilnacht" <ziga.seilnacht at gmail.com> wrote in message
news:1143306711.041441.43470 at i40g2000cwc.googlegroups.com...
> I think that True and False, although they were added in version
> 2.3, were not true singeltons until version 2.4.

OK, but Python 2.3 yields the same result as above.

Ziga  wrote:
> You should finish
> reading the PEP, see especially this part:
> - Don't compare boolean values to True or False using ==
>     Yes:   if greeting:
>     No:    if greeting == True:
>     Worse: if greeting is True:


I do not think this is relevant to the question I asked,
which was how to test for a value of True, if that's
what I really want.  I think the outcome of this
discussion has been: use 'is'.

Thanks,
Alan





More information about the Python-list mailing list