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

Jussi Piitulainen jpiitula at ling.helsinki.fi
Fri Jun 14 15:05:12 EDT 2013


Nick the Gr33k writes:

> Why return first or last value?
> 
> because that will evaluate to the correct Boolean value ????

That value will either behave exactly the same as the Boolean value
you call correct, or else it will be more useful. That is, most of the
time it doesn't matter, and when it matters, Python's way is better.

You can turn any expression E into a strictly Boolean value by writing
bool(E) instead. Often E is already guaranteed to be a Boolean and the
whole question does not arise in the first place.

This doesn't prevent you from writing your program.



More information about the Python-list mailing list