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

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Apr 3 22:27:02 EDT 2010


On Sun, 04 Apr 2010 12:26:05 +1200, Lawrence D'Oliveiro wrote:

> In message <mailman.1345.1269992641.23598.python-list at python.org>, Steve
> Holden wrote:
> 
>> Lawrence D'Oliveiro wrote:
>>
>>> By the way, you don’t need the parentheses.
>> 
>> But at the same time, if you don't *absolutely know* you don't need the
>> parentheses ...
> 
> But you can “abolutely know”—it’s all spelled out here
> <http://docs.python.org/reference/expressions.html>. Just keep that page
> open every time you write Python code.

Or, when in doubt, you can add redundant parentheses. It makes no 
difference to the runtime, and vanishingly small difference to the 
compile-time, and sometimes it aids readability.

Writing the absolutely minimal code necessary to do what you want is not 
necessarily the best approach in all cases. I find, for instance, that 
redundant parentheses aid readability of complex logical and arithmetic 
expressions, especially if you include whitespace.



-- 
Steven



More information about the Python-list mailing list