is implemented with id ?

Dave Angel d at davea.name
Wed Sep 5 09:46:31 EDT 2012


On 09/05/2012 08:48 AM, Ramchandra Apte wrote:
> On Wednesday, 5 September 2012 14:44:23 UTC+5:30, Steven D'Aprano  wrote:
>> <snip> 
>>
> Seeing this thread, I think the is statment should be removed.
> It has a replacement syntax of id(x) == id(y) and "a==True" should be automatically changed into memory comparison.

You didn't read the whole message carefully enough.  Id's can be reused,
so there are many ways to mess up comparing id's.  One is if the two
items x and y are expressions (eg. function calls).  You call a
function, and say it returns a new object, you call id() on that object,
and then the object gets discarded.  You now have a stale id, and you
haven't even evaluated the second expression yet.

It's id() which is superfluous.  But it's useful for debugging, and for
understanding.



-- 

DaveA




More information about the Python-list mailing list