Eval of expr with 'or' and 'and' within

MRAB python at mrabarnett.plus.com
Fri Jun 14 13:49:11 EDT 2013


On 14/06/2013 18:28, Michael Torrie wrote:
> On 06/14/2013 10:49 AM, Steven D'Aprano wrote:
>> Correct. In Python, all boolean expressions are duck-typed: they aren't
>> restricted to True and False, but to any "true-ish" and "false-ish"
>> value, or as the Javascript people call them, truthy and falsey values.
>> <snip>
>> There are a couple of anomalies -- the timestamp representing midnight is
>> falsey, because it is implemented as a zero number of seconds; also
>> exhausted iterators and generators ought to be considered falsey, since
>> they are empty, but because they don't know they are empty until called,
>> they are actually treated as truthy. But otherwise, the model is very
>> clean.
>
> Good explanation! Definitely enlightened me.  Thank you.
>
The general rule is that an object is true-ish unless it's false-ish
(there are fewer false-ish objects than true-ish objects, e.g. zero vs
non-zero int).



More information about the Python-list mailing list