the PHP ternary operator equivalent on Python

gene tani gene.tani at gmail.com
Fri Nov 18 14:39:19 EST 2005


Mike Meyer wrote:
> "Daniel Crespo" <dcrespo at gmail.com> writes:
>
> > Hi!
> >
> > I would like to know how can I do the PHP ternary operator/statement
> > (... ? ... : ...) in Python...
> >
> > I want to something like:
> >
> > a = {'Huge': (quantity>90) ? True : False}
> >
> > Any suggestions?
>
> Lots of ways, depending on your exact needs. What's best for what you
> suggest is "a = {Huge : (False, True)[quantity > 90]}". Googling  the

http://www.python.org/doc/faq/programming.html#is-there-an-equivalent-of-c-s-ternary-operator




More information about the Python-list mailing list