To describe it another way: 'is' does exactly what it say it does -- tests for object instance equivalence. That's _NOT_ the same as type value equivalence. Perhaps think of 'is' as doing memory address, or pointer, comparison, if you've done any C/C++ programming. If you need to do that kind of comparison, 'is' is there for you. Chances are you probably don't, and instead you're interested in value comparison, in which case you need to stick to the operators and functions that do normal value comparisons.
The 'weird' results you were seeing when using 'is' were really just the python interpretor lifting up its skirts a bit and (inadvertantly perhaps) revealing when it had shared the memory storage for a string literal and when it hadn't. On Mon, Dec 29, 2008 at 11:21 AM, David Hostetler <negative...@gmail.com> wrote: > see: http://docs.python.org/reference/expressions.html#id24 > > "Due to automatic garbage-collection, free lists, and the dynamic > nature of descriptors, you may notice seemingly unusual behaviour in > certain uses of the is operator, like those involving comparisons > between instance methods, or constants. Check their documentation for > more info." > > > As for teaching this issue, I would imagine that the appropriate > distinction needs to be made between 'is' as a built-in operator that > performs object identity comparison, vs. lexicographical comparison. > > > Also: > http://docs.python.org/library/stdtypes.html#comparisons > http://docs.python.org/reference/expressions.html#comparisons > > > On Mon, Dec 29, 2008 at 11:09 AM, Feat <j...@ai.univ-paris8.fr> wrote: >> At 16:59 +0100 29/12/08, Ronald Oussoren wrote: >>>Because strings aren't stored as unique objects. That is, there is no >>>guarantee whatsoever that 'string1 == string2' implies 'string1 is string2'. >> >> Optimization, uh? Okay, that settles it: thanks! >> >> -- >> Jym Feat ~ Paris FR 75018 >> _______________________________________________ >> Pythonmac-SIG maillist - Pythonmac-SIG@python.org >> http://mail.python.org/mailman/listinfo/pythonmac-sig >> > _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig