Message from discussion
0 == False but [] != False?
Path: g2news1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.news.ucla.edu!not-for-mail
From: James Stroud <jstr...@mbi.ucla.edu>
Newsgroups: comp.lang.python
Subject: Re: 0 == False but [] != False?
Date: Wed, 23 May 2007 22:06:31 -0700
Organization: University of California, Los Angeles
Lines: 40
Message-ID: <f336go$ro2$1@zinnia.noc.ucla.edu>
References: <1179982400.412340.178710@g4g2000hsf.googlegroups.com>
NNTP-Posting-Host: xxxxx.mbi.ucla.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: zinnia.noc.ucla.edu 1179983192 28418 128.97.39.000 (24 May 2007 05:06:32 GMT)
X-Complaints-To: abuse@ucla.edu
NNTP-Posting-Date: Thu, 24 May 2007 05:06:32 +0000 (UTC)
User-Agent: Mozilla Thunderbird 1.0.6-1.1.fc4 (X11/20050720)
X-Accept-Language: en-us, en
In-Reply-To: <1179982400.412340.178710@g4g2000hsf.googlegroups.com>
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