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

Alan Gauld alan.gauld at btinternet.com
Tue Mar 6 23:37:31 CET 2007


"David Perlman" <dperlman at wisc.edu> wrote

> Sorry, but this still doesn't make sense to me.
>
 >>> x=('i' in 'i')
 >>> x
True
 >>> y='i'
 >>> x==y
False

> But the == operator doesn't cast its operands as Booleans; 

Good catch!

I don't understand it now either.

But I've been up since 4:30am and am too tired to try 
figuring it out just now, so maybe someone else will 
explain! :-)

>>> for c in 'abcd':
...    print (c == c in 'crab')
...
True
True
True
False

It definitely seems to work as I explained it but how it works is 
defeating my befuddled brain right now. I suspect it needs 
a read of the reference manual...

Alan G.



More information about the Tutor mailing list