Say I have an Element class
class Element(object):
def __init__(self,key,val):
self.key = key
self.val = val
def __str__(self):
return '(' + str(self.key) + ',' + str(self.val) + ')'
Now when I try to print an array that contains objects of the Element class
arr = [Element(10,20),Element(20,30)]
print(arr)
, the output is -
[<maxheap.Element object at 0x01C1FCB0>, <maxheap.Element object at 0x01C270B0>]
Which function is printing <maxheap.Element object at 0x01C1FCB0>
? Why isn't the __str__(self)
method called as in print(Element(10,20))
?