the PHP ternary operator equivalent on Python
Mike Meyer
mwm at mired.org
Fri Nov 18 14:15:19 EST 2005
"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
python newsgroup will turn up lots of others.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list