is and == (is not other_thread)

Grant Griffin not.this at seebelow.org
Wed Feb 28 23:33:19 EST 2001


Hi Gang,

I've had a few of my own little questions about "is" and "==", vis-a-vis
strings:

1) Are two strings that are equal in the "==" sense always guaranteed to
be equal in the "is" sense?  Experiments I have done with the
interactive intepreter show (anecdotally, at least) that equal strings
always "is" the same, but if that's due to caching, I guess it's not
guaranteed.  (Not to mention the fact that I've found no promise in the
docs to this effect. <wink>)

2) Is "is" faster than "==" for strings?  Of hand, it would seem so. 
That's why I'm tempted to use it for string equality.  (OTOH, if strings
can be "==" equal without being "is" equal, than I guess that's wildly
false economy. <wink>)

3) Internally, does "==" for strings always begin with an "is"
operation?  (If two variables are bound to the same string, there's no
conceptual need to do the [presumably] slower operation of
character-by-character string comparison.)  If so, I guess string "=="
would be nearly as fast as string "is" in many cases.

(btw,-nobody-ever-answers-every-part-of-my-silly-multipart-questions,
   -so-i-dare-you-folks-to-buck-the-trend-<wink>)-ly y'rs,

=g2
-- 
_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation            http://www.iowegian.com



More information about the Python-list mailing list