On Thu, 3 Mar 2016 12:48 am, Chris Angelico wrote: > On Thu, Mar 3, 2016 at 12:39 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: >> Chris Angelico <ros...@gmail.com>: >> >>> Python defines that every object has an identity, which can be >>> represented as an integer. Since this is an intrinsic part of the >>> object, no two distinct objects can truly have identical >>> characteristics. Python's objects are like rifles - there are many >>> like it, but this one is mine. >> >> How can you be sure Python isn't returning the same id value for two >> distinct objects?
The language is entitled to re-use IDs provided the objects do not exist at the same time. So there certainly will be times that Python will return the same ID for different objects: py> id([1]) 3083419340L py> id([2]) 3083419340L > The same way I can be sure about anything else in Python. It's a > language guarantee. If you're bothered by that, you should also be > concerned that str(x) might not actually call x.__str__(), Technically, it doesn't, it calls type(x).__str__() (at least in Python 3 and new-style classes in 2) :-) But your point is broadly correct: you trust the language to do what it promises, or you look for evidence that it doesn't and report a bug if you find it. -- Steven -- https://mail.python.org/mailman/listinfo/python-list