PEP 308: Alternative conditional operator forms
Andrew Dalke
adalke at mindspring.com
Mon Feb 10 04:39:13 EST 2003
Paul Rubin:
> PEP 308 is motivated by the frequently asked question of "how do I do
> something like ?:" and the recognition that the answers that result
> are unsatisfactory to a lot of us.
But add the condition that "usually when asked it turns out the person
who asked the question didn't realize there was another, better answer
which was available in Python without using the ternary if/else expression"
I gave as some examples
x if x < y else y
when
min(x,y)
is available, or
hex_c = chr(48 + i if i < 10 else 55 + i)
when
hex_c = "0123456789ABCDEF"[i]
and
hex_c = ("%x" % i)[2:]
both exist.
Therefore this proposal must take into account that people will
use it incorrectly (based, eg, on experiences in other langauges)
to the overall detriment of the program.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list