Trinary operator?

Berthold Höllmann hoel at germanlloyd.org
Thu Apr 25 04:08:39 EDT 2002


Jeff Shannon <jeff at ccvcorp.com> writes:

> In article <871yd4odap.fsf at pvv.org>, oyving+news at pvv.org says...
> > * Cliff Wells
> > |
> > | On 24 Apr 2002 22:57:20 +0200
> > | Oyvind Gronnesby wrote:
> > | 
> > | > * Cimarron Taylor
> > | > |
> > | > | Will this do what you want?
> > | > | 
> > | > | verboseGender = ('female','male')[gender=='m']
> > | > 
> > | > Wouldn't this break in a PEP 285 Python world?
> > | 
> > | No.  That was the whole point of subclassing bool from int.
> > 
> > But wouldn't that just imply that True/False would turn into 1/0 if coerced
> > into it by int()?
> 
> Yes, they will.  This is by design, to maintain backwards 
> compatibility.  The only effective difference between 1 and True, 
> and 0 and False, is how it's written, but they add, subtract, 
> multiply, and hash the same.

But there is a difference:

>python
Python 2.2.1 (#1, Apr 10 2002, 17:11:02) 
[GCC 3.0.4] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1
>>> b = 1
>>> a is b
1
>>> a = True
>>> a is b
0
>>> 

Greetings

Berthold
-- 
Dipl.-Ing. Berthold Höllmann   __   Address:
hoel at germanlloyd.org        G /  \ L Germanischer Lloyd
phone: +49-40-36149-7374    -+----+- Vorsetzen 32/35    P.O.Box 111606
fax  : +49-40-36149-7320      \__/   D-20459 Hamburg    D-20416 Hamburg



More information about the Python-list mailing list