Suppose I create a class in python, but I don't define a __cmp__
method for my class. Now I create two instances of that class and compare them. What cmp method does Python use? I ran the code and it returns false when comparing for equality. Does Python compare memory addresses?
class A(object):
def __init__(self, s):
self.s = s
def __str__(self):
return self.s
x1 = A("jim")
x2 = A("jim")
print x1 == x2
Shell says:
False
lambda x,y: id(x)==id(y)
if memory serves.