Integration with Python Operator overloading : comparison Object equality
1 2 3 4 5 6 7 8 |
class Customer: def __init__(self, name, balance): self.name, self.balance = name, balance cust1 = Customer("John Fisher", 2100) cust2 = Customer("John Fisher", 2100) cust1 == cust2 > False |
Variables are references
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
class Customer: def __init__(self, name, balance, id): self.name, self.balance = name, balance self.id = id cust1 = Customer("John Fisher", 2100, 123) cust2 = Customer("John Fisher", 2100, 123) cust1 == cust2 > False print(cust1) <__main__.Customer at 0x16549e8e78> print(cust2) <__main__.Customer at 0x16549e7e51> |
Due to the fact how the objects and variables representing them are stored printing the value of the (customer) object –> prints the memory allocation chunk the value = reference to the memory chunk ))> so when comparing we are […]