"0 in [True,False]" returns True

Steven Bethard steven.bethard at gmail.com
Tue Dec 13 01:34:26 CET 2005

Pierre Quentel wrote:
> In some program I was testing if a variable was a boolean, with this 
> test : if v in [True,False]
> My script didn't work in some cases and I eventually found that for v = 
> 0 the test returned True

This seems like a strange test.  What is this code trying to do?

If you're sure you have to do this, I would do either:

     if isinstance(v, bool):


     if v is True or v is False:

But it really seems like this code is trying to code some other language 
in Python...


More information about the Python-list mailing list