On Tue, 30 Mar 2010 08:40:56 -0700, gentlestone 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)]
You don't need the call to bool.
('No','Yes')[a==b]
> Is there a more elegant/common python expression for this?
The above is pretty elegant to my eyes, but you can also do:
return 'Yes' if a==b else 'No'
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
