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

Joaquin Abian gatoygata2 at gmail.com
Tue Mar 30 12:57:34 EDT 2010


On Mar 30, 5:40 pm, gentlestone <tibor.b... at hotmail.com> wrote:
> Hi, how can I write the popular C/JAVA syntax in Python?
>
> Java example:
>     return (a==b) ? 'Yes' : 'No'
>
> My first idea is:
>     return ('No','Yes')[bool(a==b)]
>
> Is there a more elegant/common python expression for this?

(a==b) and 'YES' or 'NO'

Yes, ugly

Joaquin



More information about the Python-list mailing list