question about True values

J. Clifford Dyer webmaster at cacradicalgrace.org
Sat Oct 28 23:32:38 CEST 2006


Steven D'Aprano wrote:
> On Sat, 28 Oct 2006 03:13:42 +0100, Steve Holden wrote:
 >
>>> Finally, while True/False is a good mental mapping for numeric 
>>> comparisons, take the following:
>>>
>>>  >>> if "Cliff is a pillar of the open source community":
>>> ....	print "thank you"
>>> .... else:
>>> ....	print "bugger off"
>>>
>>> bugger off
>>>

First off, even though nobody has called me on it, this example really 
prints "thank you", not "bugger off".  I got confused in my cutting and 
pasting.  Sorry about that.


>>> Clearly this is not true.  (Google Cliff/Dyer open source: only 11 
>>> hits.), but the string is *something* so the if block gets evaluated.
>>>
>>   >>> if "The above example was bollocks":
>>   ...   print "You don't know what you are talking about"
>>   ... else:
>>   ...   print "Sorry: of course you are perfectly correct"
>>   ...
>> You don't know what you are talking about
> 
> Cliff is making a point about semantics, and he's absolutely correct about
> it, although it is irrelevant since we're talking about two-value logic
> not semantics.
> 
> 
> 
> 

Thank you for the clarification Steven (D'Aprano).  To a certain level, 
I agree that semantics are important.  I hesitated about including that 
example in my post to begin with.  However, my point, and hopefully I'll 
be able to make it more clearly now, was that true/false is a useful way 
to think regarding logical statements like x == 3, but that when you are 
dealing with strings, or more accurately strings that represent 
language, you really aren't talking about truth any more, because in 
that context, truth cannot be divorced from semantics--somethingness, on 
the other hand, can.

Conceptually, you have to go through "'something' is true, and 'nothing' 
is false" before it makes sense.

On the other hand, (to play devil's advocate for a moment), when you are 
dealing with comparison operators, you have to go through "true 
statements yield something and false statements yield nothing" before it 
makes sense, or rather "yield a nothing value."  So either way you think 
about it, you have to, in some cases, mentally convert from truthiness 
to somethingness or vice versa.  I don't find it as odious to mentally 
convert the comparison operators as I do the declarative statements.  I 
don't think it's just a personal preference either, because that way 
your mental processes are in sync with the way python works.  It 
evaluates if the statement is true and yields a something value, and a 
nothing value if it's false.  You are working with the Tao of Python, if 
you'll forgive the analogy.  However thinking in terms of truth and then 
saying that all statements that exist are true works, but runs counter 
to what is going on behind the scenes.

Or maybe it doesn't, if everything's getting converted implicitly to 
bool anyway.  Maybe it is just personal preference after all.  But then 
bools are assigned "something" and "nothing" values....

This stuff is tricky, but I'm enjoying trying to wrap my mind around it, 
and appreciating the comments and critiques.

Cheers,
Cliff



More information about the Python-list mailing list