Claudio Grondi wrote: [...] >> > Yes, I know about 'is', > > but I mean, that it is not possible to use 'is' as replacement for '==' > operator to achieve in Python same behaviour as it is the case in C and > Javascript when comparing values with '=='. > 'is' does the C, Javascript job when comparing lists, but I mean it > fails to give fully predictable results when applied to elements of > lists in case there exist duplicate objects with same 'value' i.e. e.g. > there are two different objects storing the integer value 1, what I mean > can happen when there is enough other code between the Python code lines > assigning the integer value 1 to a list element or any other identifier.
Perhaps you could try again in English? :-) Sorry, that's a very complex sentence and it isn't clear what yo mean. In C, of course, a == b requires that a and b be of compatible types and that they have the same value. This means that if they are pointers they must point to the same thing (which is exactly what "is" tests for). > Or is there in Python a 100% reliable mechanism assuring, that there is > one and _only one_ object carrying a given 'value' (at least for the > built in types as integer, long integer, string, float) and if this > value is to be assigned to a list element or any other literal the > already existing object (if any) will be found and used/referenced? > No more than there is in C or, presumably, Java. If you want to test for identity, use "is". If you want to test for equality, use "==". Of you want to test for something else, kindly explain what you want to test for. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list