I am new to python. I have a few questions coming from an armature!

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Thu Aug 18 03:22:39 EDT 2016


Terry Reedy writes:
> On 8/17/2016 2:39 AM, Steven D'Aprano wrote:

[- -]

>> Because the C syntax is horrifically ugly, whereas the Python syntax
>> is very close to real English syntax.
>>
>> "What will you do tonight?"
>>
>> "Go to the movies, if I finish work on time, otherwise just go home."
>
> "If I finish work on on time, go to the movies, otherwise just go
> home."  is also real English syntax, and to me, more graceful.  It is
> certainly more neutral among the alternatives.  The inverted version
> implies a clear preference for the first alternative.

Conditional expressions should be compared to a more marginal English
construction where the two branches are noun phrases, or adverbial
phrases, or any other such phrases that are not statements or clauses.
Because, as expressions, conditional expressions stand for the value,
and any other intended effect should be considered an abuse of the
notation.

"Movies, if I finish on time, otherwise just home."
"If I finish on time, to the movies, otherwise just home."

"Coffee, if it's available, else spam."
"If there's coffee, then coffee, else spam."
"If there's coffee, then that, else if there's spam, then spam."

"One or more, unless the codomain is empty." # no else branch

I'm sure my ear is not reliable here, and I don't quite trust anybody's
made-up examples, and I would want to see naturally occurring examples
in their natural habitat, so ...

> It would be an interesting exercise to see which order for ternary
> expressions is more common in some large corpus of English text.

... yes. That's bound to be subtle and varied, and not at all conclusive
for a formal-language syntax, but definitely interesting. Perhaps even
better would be a grammarian's account of such observations. I'll see if
that copy of Huddleston and Pullum is still in our mail room.

But please consider calling them conditional expressions. Even K & R do.

[- -]



More information about the Python-list mailing list