This site is best viewed in Mozilla Firefox or Google Chrome
Fri, 18th May 2012 03:59:00
Never fear, this site is here  

Go back to post Create new comment

#

Since Python 2.5 you can do ternary operations like so:

f() if h() else g()

http://docs.python.org/reference/expressions.html

Dive into Python also gives a good overview of solving it the long way:

http://diveintopython.org/power_of_introspection/and_or.html

Last edited by doug on Sun, 18th Jul 2010 21:24:54

Go back to post

Create a new comment

Go to the top
For post: Ternary operator in Python
Your name:
Your email (optional):
Your website (optional):
 
 
 

A preview of your comment:

Powered by Debian, Jack Daniels, Guinness, and excessive quantities of caffeine and sugar.