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

Larry Hudson orgnut at yahoo.com
Sat Jun 15 01:27:52 EDT 2013


On 06/14/2013 09:56 AM, Nick the Gr33k wrote:
> On 14/6/2013 7:31 μμ, Steven D'Aprano wrote:
>> On Fri, 14 Jun 2013 16:07:56 +0300, Nick the Gr33k wrote:
>>

>
> Returning True is the same thing as returning a variable's truthy value?
>
NO!  'True' and 'False' are the two values of the boolean type.  The 'and' and 'or' logical 
operators do NOT return a boolean type of True or False.  (Although, the 'not' DOES return a 
boolean.)

Also they do NOT return "a variable's truthy value", they return the variable itself.  Now, that 
returned variable can then be interpreted as a boolean value for other operations in the same 
way that (virtually) all data types can be interpreted as a boolean.  Let me emphasize... they 
are INTERPRETED as having a boolean VALUE, but they are NOT a boolean TYPE.

>
>  >>> (a and b and c)
> 'ijkl'
>
> This in my head should have been evaluated to True also since all 3 strings hold truthy values
>
You need to get it into your thick head that you are mistaken, like everyone is trying to tell 
you.  What YOU think about it is WRONG!  Throw that thinking away and start LISTENING to what 
you are being told are the facts.

> Why on earth this boolean expression evaluates to the value of the last variable? This is what
> can't at all seem to follow.
>
BECAUSE THAT IS THE WAY PYTHON IS DEFINED, whether or not you agree with it.  You are WRONG!  It 
is time for you to accept the fact that you are mistaken and start trying to learn how Python IS 
defined -- NOT how YOU think it should be defined.

>
> 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.
>
I repeat:  what YOU think Python should do is completely irrelevant.  If you keep insisting on 
trying to use Python they way you THINK it should work instead of the way it is DEFINED to work, 
you'll lose that argument every time.

The whys of how Python works is, frankly, not important -- interesting and useful perhaps, but 
essentially irrelevant.  Just keep writing Python in the way it is defined, and learning the 
whys will come along.





More information about the Python-list mailing list