(a==b) ? 'Yes' : 'No'

MRAB python at mrabarnett.plus.com
Tue Mar 30 23:43:04 CEST 2010

Robert Fendt wrote:
> And thus spake John Bokma <john at castleamber.com>
> Tue, 30 Mar 2010 13:19:19 -0600:
>> And
>>  a == b and 'Yes' or 'No' 
>> isn't a Perl-ism?
> I never said that this would be better. I don't even get the
> point of what the advantage is supposed to be of inverting the
> order of the return statement and the conditional check what
> should actually _be_ returned. What's wrong with just writing
> if a==b:
>   return 'Yes'
> else:
>   return 'No'
> apart from it being a few more line breaks and an additional
> return statement? The inverted form is not more readable per
> se (in fact, quite the opposite), and I would even suggest to
> minimise its use even in languages like C++ and Java. The Python
> syntax is even worse since it not only inverts the order of
> return statement and conditional check, but it also puts the
> conditional between the two results.
> I find such a convoluted construct especially ugly in a language
> which I previously regarded as having a rather striking beauty
> of syntactical simplicity. The construct is superfluous,
> illogical, unelegant, and thus very un-pythonesque, IMHO. But of
> course that's just my $0.02.
I think you mean that it's very _un-Pythonic_ (perhaps because it's very
very Pythonesque)! :-)

>> Sheesh, this group would be so much nicer without the constant dragging
>> in of Perl to make a point. On top of that, do {  } unless blocks are
>> not idomatic in Perl. Perl Best Practices even clearly states to *never*
>> use unless.
> Sorry, but you have just underlined my point, in fact. If it's
> discouraged by experts, then of course the question must be
> valid why such a feature even exists (okay, apart from 'it
> seemed like a good idea at the time'). And more importantly (and
> more on-topic here), why we have to have an analogon in Python.

More information about the Python-list mailing list