"0 in [True,False]" returns True
Carsten Haese
carsten at uniqsys.com
Mon Dec 12 16:38:31 EST 2005
On Mon, 2005-12-12 at 16:26, Pierre Quentel wrote:
> 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 ?
Where/how did you search? http://docs.python.org/lib/typesseq.html
states unambiguously that "x in s" returns "True if an item of s is
equal to x, else False"
HTH,
Carsten.
More information about the Python-list
mailing list