0 == False but [] != False?
James Stroud
jstroud at mbi.ucla.edu
Thu May 24 01:06:31 EDT 2007
Rajarshi wrote:
> This is a slightly naive question, but I know that 0 can be used to
> represent False. So
>
>
>>>>0 == False
>
> True
>
> But, I know I can use [] to represent False as in
>
>
>>>>if not []: print 'empty'
>
> ...
> empty
>
> But then doing the following gives a surprising (to me!) result
>
>
>>>>[] == False
>
> False
>
> Could anybody point out why this is the case?
>
> Thanks,
> Rajarshi
>
Meditate on:
py> isinstance(False, int)
True
py> isinstance([], int)
False
py> bool([])
False
James
More information about the Python-list
mailing list