From: Dotan Cohen on 19 Apr 2010 08:16 On 30 March 2010 18:40, gentlestone <tibor.beck(a)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. |