0 == False but [] != False?

Paul McGuire ptmcg at austin.rr.com
Thu May 24 01:11:22 EDT 2007


On May 23, 11:53 pm, Rajarshi <rajarshi.g... at gmail.com> 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

This has *got* to rank up there among the VFAQ's of them all, along
with the mysterious shared default empty list argument.  I think this
particular question has been asked in one form or another at least
twice a week for the past month!

-- Paul




More information about the Python-list mailing list