PEP 308: Alternative conditional operator forms
adalke at mindspring.com
Mon Feb 10 10:39:13 CET 2003
> 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
is available, or
hex_c = chr(48 + i if i < 10 else 55 + i)
hex_c = "0123456789ABCDEF"[i]
hex_c = ("%x" % i)[2:]
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.
dalke at dalkescientific.com
More information about the Python-list