Explaining names vs variables in Python

Chris Angelico rosuav at gmail.com
Wed Mar 2 08:48:35 EST 2016


On Thu, Mar 3, 2016 at 12:39 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at 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 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__(), or that
a+b*c might evaluate the addition before the multiplication.

ChrisA



More information about the Python-list mailing list