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

Andreas Kostyrka andreas at kostyrka.org
Fri Feb 16 16:20:53 CET 2007


* Wolfram Kraus <wolfram.kraus at fen-net.de> [070216 15:23]:
> 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"

In earler versions:

((a>b) and "Yes") or "NO"

Andreas


More information about the Tutor mailing list