| |
comp.lang.python |
>>>> 0 == False > But, I know I can use [] to represent False as in >>>> if not []: print 'empty' > But then doing the following gives a surprising (to me!) result >>>> [] == False > Could anybody point out why this is the case? -- "I have come to believe that the whole world is an enigma, a harmless enigma
> This is a slightly naive question, but I know that 0 can be used to
> represent False. So
> True
> ...
> empty
> False
"bool(foo)". For empty lists, strings, tuples, dicts and some other things,
"bool(foo) == False", while for lists, etc., with at least one element,
"bool(foo) == True".
Robert Kern
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco