Trinary operator?
Jeff Shannon
jeff at ccvcorp.com
Wed Apr 24 21:25:59 EDT 2002
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.
--
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list