The ternary operator is a way to concisely say:
“If test, then a, else b“,
with the value of the statement being the value of a or b.
a if test else b
**Why??</strong?
Why??
Ok. Now that I’ve written this post, I’ll remember it.
However, I just want to say…
On behalf of all of the other multiple-language programmers in the world, …
THIS IS LAME!!!
Update: No really, why??
Well, there are some reasonable reasons.
As noted in the comments, the Python version is more readable (at least in English).
And, to tell you the truth, if I ONLY were programming in Python, I’d probably prefer the Python version.
However, I don’t. I spend quite a bit of time in C++, Perl, PHP, and javaScript. And they ALL use the other form!
Well, there are some reasonable reasons.
As noted in the comments, the Python version is more readable (at least in English).
And, to tell you the truth, if I ONLY were programming in Python, I’d probably prefer the Python version.
However, I don’t. I spend quite a bit of time in C++, Perl, PHP, and javaScript. And they ALL use the other form!
I understand the reasoning behind Python’s version.
I JUST DON’T AGREE WITH IT!
<h2>
Rant over
</h2>
<p>
Glad I’ve gotten that off my chest.
</p>