| |
comp.lang.python |
> Could anybody point out why this is the case? In your case, writing "if []" translates to True and False are of type bool which is a subclass In contrast, the empty list is not of type int. Raymond
> False
Evaluating bool(x) checks for a x.__nonzero__()
and if that method isn't defined, it checks for
x.__len__() to see if x is a non-empty container.
"if len([]) != 0", which evaluates to False.
of int. So, False really is equal to zero and
True really is equal to one.
So [] != False eventhough bool([]) == False.