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

Dotan Cohen dotancohen at gmail.com
Mon Apr 19 08:16:49 EDT 2010


On 30 March 2010 18:40, gentlestone <tibor.beck 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?
>

I'm a little late to the party, but I just saw this in Dive Into Python:
multiple = 1024 if a_kilobyte_is_1024_bytes else 1000

It's kind of sloppy as the condition is between the possible values,
but it works.

-- 
Dotan Cohen

http://bido.com
http://what-is-what.com

Please CC me if you want to be sure that I read your message. I do not
read all list mail.



More information about the Python-list mailing list