3 ms·
When first learning python (Shaw's The Hard Way maybe), it suggested this idiom as python's ternary operator: boolean and true_branch or false_branch and
by SilasX 12y ago
When first learning python (Shaw's The Hard Way maybe), it suggested this idiom as python's ternary operator:
boolean and true_branch or false_branch
and explained that boolean=true would make it check and return true_branch, while false makes it check the other side of the or.
This is parallel to the standard C one. I'm surprised no one has mentioned it, but I guess that makes sense because it's not very explicit about what it's doing, which goes agains the spirit of python. Probably not very common for python programmers to use.