The three things that could be better in Python

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
        return b
true = True
false = False

Comment written by Joe Shaw at 2008-12-01 18:14:10 GMT:

A ternary operator was added to Python 2.5. The syntax is different from C-style, though. Instead of:

foo ? bar : baz

you have:

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.

Comment written by Laci at 2008-12-02 01:40:57 GMT:

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.