[Tutor] trouble with function-- trying to check differences btwn 2 strings

David Perlman dperlman at wisc.edu
Tue Mar 6 23:09:02 CET 2007


On Mar 6, 2007, at 11:03 AM, Alan Gauld wrote:
> It's doing the latter and since anything that's not 'empty' in
> Python evaluates to true we wind up checking whether
> true == (item in word)
>
> So if the item is in word we get true == true which is true.
>
> HTH,

Sorry, but this still doesn't make sense to me.

 >>> x=('i' in 'i')
 >>> x
True
 >>> y='i'
 >>> x==y
False

I understand that anything that's not 'empty' or zero evaluates to  
True *when cast as a Boolean* by the operation in question:

 >>> if y: print "It's True!"
...
It's True!

But the == operator doesn't cast its operands as Booleans; it merely  
*returns* a Boolean.

Or is the point that in the original case the == operator *is*  
casting item to Boolean because it's comparing it with another  
Boolean?  That's kind of strange, especially considering that in my  
example above, it *didn't* do that.

I still don't understand what's going on.  :)

--
-dave----------------------------------------------------------------
Science arose from poetry... when times change the two can meet again
on a higher level as friends. -Göthe




More information about the Tutor mailing list