The ternaery operator

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Mar 16 17:13:41 EDT 2017


Tobiah wrote:
> To be fair, the proper comparison would be:
> 	
> 	If it's Tuesday, I wear my red shirt, else my green one.

The Python analog of that would be

    if it_is_tuesday:
       wear(red_shirt)
    else:
       wear(green_shirt)

i.e. a statement rather than an expression. We're looking
for an English analog of a conditional expression:

    wear(red_shirt if it_is_tuesday else green_shirt)

For that, we need a conditional noun phrase, and the
only way to get one of those in English without sounding
like a non-native speaker is to put the condition in
the middle.

-- 
Greg



More information about the Python-list mailing list