In Python the id() function should never be used to check the equality of two objects.
id() function returns an integer representation of the object's identity, which is always different even if two or more instances of a class have exactly the same attributes and the same values for those attributes . At the CPython implementation level, it is the address of the object in memory.
class User: def __init__(self, name): self.name = name user_1 = User('John') user_2 = User('John') print(id(user_1)) print(id(user_2))
We will get for example:
As you can see, the
id() function returns two different values.