weird behaviour of "0 in [] is False"

Scott David Daniels Scott.Daniels at Acm.Org
Tue Nov 30 21:15:11 CET 2004


Sylvain Thenault wrote:
> Hi there !
> 
> Can someone explain me the following behaviour ?
> 
> 
>>>>l = []
>>>>0 in (l is False)
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: iterable argument required
> 
>>>>(0 in l) is False
> 
> True
> 
>>>>0 in l is False
> 
> False
> 
> 
> This is really obscur to me...
> 
A suggestion:
When discussing things on the newsgroup (and in your code), avoid
symbols like "l" and "O" -- they look too much like numbers.  Picking
an actual name is best (but depends on your application context).
Second best are names like: "lst", "obj", ...: often, however, such
names are necessary when discussing abstract code properties.

-Scott



More information about the Python-list mailing list