A certainl part of an if() structure never gets executed.

Chris Angelico rosuav at gmail.com
Fri Jun 14 13:18:02 EDT 2013


On Sat, Jun 15, 2013 at 2:56 AM, Nick the Gr33k <support at superhost.gr> wrote:
> What i'm trying to say that both these exprs are Boolean Expressions
> therefore should return Boolean values not variable's values, even if they
> are truthy.

Okay, now we get to the nub of the matter.

In some languages, what you say is the case. In C, for instance, 3 ||
4 == 1 (C doesn't have dedicated True and False types, it uses 1 and
0). But there are very few situations where you actually need it to
specifically be the boolean values, and plenty where you can make use
of this additional feature. If you want to demand a bool from Python,
there is a way to do this. Experiment with bool() in the interactive
interpreter.

ChrisA



More information about the Python-list mailing list