[Tutor] how to wirte code In python :str = (a>b?"Yes":"NO")

Michael P. Reilly arcege at gmail.com
Fri Feb 16 15:09:50 CET 2007


On 2/16/07, Wolfram Kraus <wolfram.kraus at fen-net.de> wrote:
>
> On 16.02.2007 08:01, xiufeng liu wrote:
> > Hi, all,
> >
> > In python if there is any similar way like in Java, or C++ to express
> > the following:
> > str = (a>b?"Yes":"NO")
> >
> >
> > thanks!
>
> In Python 2.5 you can do the following (untested):
>
> str = "Yes" if a>b else "No"
>
> See: http://docs.python.org/whatsnew/pep-308.html
>
> HTH,
> Wolfram
>

Before 2.5, you could generally write:

str = (a > b) and "Yes" or "No"

  -Arcege

-- 
There's so many different worlds,
So many different suns.
And we have just one world,
But we live in different ones.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070216/071d8ca2/attachment-0001.html 


More information about the Tutor mailing list