2008-12-01 06:19:57 GMT
2008-11-02 update: The legendary Joe Shaw made me realize (in the comments below) that there's a (very unintuitive) ternary operator for Python from Python 2.5 which one can use as:
a if condition else b
Python is my favorite scripting language. I think it's almost perfect and there are almost no things that could be improved in it. Almost...
def T(condition, a, b): if condition: return a else: return b
true = True false = False
A ternary operator was added to Python 2.5. The syntax is different from C-style, though. Instead of:
foo ? bar : baz
bar if foo else baz
which I find to be a lot more confusing, but I guess it suggests that the else clause is the less likely case to occur.
Thanks for bringing this to my attention, Joe! The if - else construct works for me like a charm, although I also find this syntax confusing.