Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Duncan Booth Newsgroups: comp.lang.python Subject: Re: Equivalent code to the bool() built-in function Date: 18 Apr 2011 10:01:22 GMT Lines: 37 Message-ID: References: <4da9fb0b$0$13696$426a74cc@news.free.fr> <87k4etho6e.fsf@benfinney.id.au> <4daa2b72$0$32037$426a74cc@news.free.fr> <87d3klha85.fsf@benfinney.id.au> <4daaa6f6$0$20187$426a74cc@news.free.fr> <878vv9gqhq.fsf@benfinney.id.au> <4dab7654$0$7290$426a74cc@news.free.fr> <4dab845d$0$29986$c3e8da3$5496439d@news.astraweb.com> Reply-To: duncan.booth@suttoncourtenay.org.uk Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: individual.net V2H8x9p18qymxQtyG5bS+ge3oKGLNOIsbeZwDOUnxaFNx0jTXm Cancel-Lock: sha1:ZpAlhlvfboO6TcFe0gk+zw58VPk= User-Agent: Xnews/2006.08.24 Hamster/2.1.0.11 X-Face: .C;/v3#w@2k.C(.1v-}d=`|7AQ-%,#A$0ZGtAkLPvuawAM>3#D,pXaAb31%(=Gn2ZZK/Z~fd0y4't5iKK~F":}F2*|\mQYX+BUr4ZM*|+`@o-TKzFGwsJnan{)*b~QJ-Fu^u'$$nYV Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3481 Steven D'Aprano wrote: > So in Python 2.2, Python introduced two new built-in names, True and > False, with values 1 and 0 respectively: > > [steve@sylar ~]$ python2.2 > Python 2.2.3 (#1, Aug 12 2010, 01:08:27) > [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> True, False > (1, 0) >>>> type(True) > > Also in Python 2.2 (and I think earlier but I don't have anything earlier to check) there was an interesting property that while all other integers from -1 to 99 were optimised to share a single instance, there were actually 2 instances of 0 and 1: Python 2.2.3 (#1, Sep 26 2006, 18:12:26) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-56)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 2-1 is 1 1 >>> True is 1 0 >>> (True is 1) is 0 0 >>> (True is 1) is False 1 The code for the win32api made use of this fact to determine whether to pass int or bool types through to COM methods. -- Duncan Booth http://kupuguy.blogspot.com