Python's and and Pythons or

Peter Cacioppi peter.cacioppi at gmail.com
Wed Oct 9 19:54:03 EDT 2013


I really like the logic that Pythons "or" is not only short-circuit but non-typed.

So I can say

y = override or default

and y won't necc be True or False. If override boolean evaluates to True (which, for most classes, means not None) than y will be equal to override. Otherwise it will be equal to default.

I have two questions
--> Is there a handy name for this type of conditional (something as catchy as "short circuit or")

and 

--> Is there a common idiom for taking advantage of the similar behavior of "and". The "override or default" just makes me grin every time I use it.

Thanks



More information about the Python-list mailing list