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

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Mar 30 19:11:29 CEST 2010

On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote:

>> Yes, Python has ternary operator-like syntax: return ('Yes' if a==b
>> else 'No')
>> Note that this requires a recent version of Python.
>      Who let the dogs in?  That's awful syntax.

I used to think so to, but now I like it. It matches common English 
syntax like:

"I'm going to the movies tonight, if I leave the office early, otherwise 
I'll stay home and nitpick on Usenet."


More information about the Python-list mailing list