[Python-Dev] Suirprise!

Guido van Rossum guido@digicool.com
Sat, 21 Apr 2001 06:42:09 -0500


> I just stared at this a long time:
> 
> >>> 'a' in 'a'  # fine
> 1
> >>> 'a' in 'a' == 1  # what?
> 0
> >>> 'a' in 'b'  # fine
> 0
> >>> 'a' in 'b' == 0  # what?
> 0
> >>>
> 
> It's "correct".  I've been using Python longer than Guido <wink>, and I'm
> amazed this is the first time I got bit by this!  Here's a hint:
> 
> >>> 'a' in 'a' == 'a'
> 1
> >>>
> 
> thank-god-for-dis.dis-ly y'rs  - tim

Yeah, I ran into the same when converting some has_key() tests to
using 'in'.  I guess it's not very common since nobody in their right
minds should want to compare the result of an 'in' test to anything
else.  The has_key() tests did something like "assert d.has_key(k)==1"
and the mindless translation of that is "assert k in d == 1"...

Didn't-need-dis-though-ly y'rs,

--Guido van Rossum (home page: http://www.python.org/~guido/)