Vote on PEP 308: Ternary Operator

Tim Evans t.evans at
Mon Mar 3 10:29:13 CET 2003

pep308vote at (Raymond Hettinger) writes:

> Write-out these five examples using your most preferred syntax:
>     x = "door" + (if quantity>1: "s" else: "")

Resulting in "You have opened 0 door"?  So maybe that should be
'quantity != 1'.  Also, what if you change 'door' to a word where
adding a traling 's' doesn't make the plural, or translate to a
language where it never does?  This would be better (IMHO):

x = (if quantity != 1: "doors" else: "door")

>     data = (if hasattr(s, 'open'): s.readlines() else: s.split())

s.split('\n') perhaps?

>     z = 1.0 + (if abs(z) < .0001:  0 else: z)
>     t = v[index] = (if t<=0: t-1.0 else: -sigma /(t + 1.0))
>     return (if len(s)<10: insertsort(s) else: quicksort(s))
> Note, the examples are required but will not be used.
> Try to get them right, but it is okay if they are wrong.

yes-I'm-nit-picking-ly yours
Tim Evans

More information about the Python-list mailing list