"0 in [True,False]" returns True

Pierre Quentel quentel.pierre at wanadoo.fr
Mon Dec 12 22:26:47 CET 2005


Hi all,

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

So I changed my test for the obvious "if type(v) is bool", but I still 
find it confusing that "0 in [True,False]" returns True

By the way, I searched in the documentation what "obj in list" meant and 
couldn't find a precise definition (does it test for equality or 
identity with one of the values in list ? equality, it seems) ; did I 
miss something ?

Regards,
Pierre



More information about the Python-list mailing list