Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion 0 == False but [] != False?

View parsed - Show only message text

Path: g2news1.google.com!news4.google.com!news.germany.com!feed.xsnews.nl!border-1.ams.xsnews.nl!feeder1.cambrium.nl!feed.tweaknews.nl!62.216.30.27.MISMATCH!newsgate.cistron.nl!xs4all!transit1.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path: <python-python-l...@m.gmane.org>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@bag.python.org
X-Spam-Status: OK 0.013
X-Injected-Via-Gmane: http://gmane.org/
To: python-l...@python.org
From: Robert Kern <robert.k...@gmail.com>
Subject: Re: 0 == False but [] != False?
Date: Thu, 24 May 2007 00:05:02 -0500
Organization: The Church of Last Thursday
References: <1179982400.412340.178710@g4g2000hsf.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Gmane-NNTP-Posting-Host: 216-188-226-33.dyn.grandenetworks.net
User-Agent: Thunderbird 2.0.0.0 (Macintosh/20070326)
In-Reply-To: <1179982400.412340.178710@g4g2000hsf.googlegroups.com>
Sender: news <n...@sea.gmane.org>
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: General discussion list for the Python programming language
	<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.8101.1179983139.32031.python-list@python.org>
Lines: 33
NNTP-Posting-Host: 194.109.207.14
X-Trace: 1179983140 news.xs4all.nl 329 [::ffff:194.109.207.14]:41016
X-Complaints-To: abuse@xs4all.nl

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?

"if foo:" does not check if "foo == True" or "foo == False" but rather
"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

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco


Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google