Alex headshot

AlBlue’s Blog

Macs, Modularity and More

Python 2.5 released

2006, python

Python 2.5 has been released, with a bunch of new enhancements such as conditional expressions. What's interesting about this particular feature is the syntax; more specifically, the ordering:

x = true_value if condition else false_value

Counter-intuitively, this evaluates out-of-order; the condition is evaluated first, then (if it's true) the true_value is evaluated; or false_value if not. But what's particularly brave is that I don't know of any other language that uses this syntax, yet the argument is simple enough; most of the time, you're wanting to use one side of the choice, and fall back to another value if a condition doesn't hold. For example, you might have something like:

x = y if y != null else ""

It's a neat idiom, and particularly pythonic. I just wonder if it will catch on in other languages...