Ternary conditional operator: Difference between revisions

Content deleted Content added
+haskell
Capi (talk | contribs)
Python: the if-then-else expression only exists as of Python 2.5. Mention this, and offer an alternative that always works.
Line 61:
The Python programming language uses a different syntax for this operator:
<source lang="python">value_when_true if condition else value_when_false</source>
This feature is not available for Python versions prior to 2.5, however. The [http://www.python.org/doc/faq/programming/#is-there-an-equivalent-of-c-s-ternary-operator Python programming FAQ] mentions several possible workarounds for these versions, with varying degrees of simplicity versus semantic exactness (for example, regarding the [[short-circuit evaluation]] property of ?:). The most complete alternative, that has all the same properties as ?: and still works in Python versions prior to 2.5, would be:
<source lang="python">(a and [b] or [c])[0]</source>
 
===Result type===