Python's and and Pythons or
Peter Cacioppi
peter.cacioppi at gmail.com
Thu Oct 10 02:55:50 EDT 2013
On Wednesday, October 9, 2013 4:54:03 PM UTC-7, Peter Cacioppi wrote:
> 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
So you can wrap it all up in one big example
y = (overrideprovider and overrideprovdider() ) or default
echo-argument and/or is a beautiful thing
More information about the Python-list
mailing list