Been a reader for some months but this is my first post (open to feedback in improving posting). I have gone through the fundamentals of Python and OOP and want to understand memory better:
class Foo(): pass
class Bar():
def __repr__(self):
standard_ouput = f'<{__name__}.{type(self).__name__} object at {hex(id(self))}> (override)'
return standard_ouput
f = Foo()
b = Bar()
print(Foo())
print(f)
print(Bar())
print(b)
The above code outputs some variation of:
<__main__.Foo object at 0x1079973c8>
<__main__.Foo object at 0x107997358>
<__main__.Bar object at 0x1079973c8> (override)
<__main__.Bar object at 0x107997400> (override)
1). Why do Foo()
and Bar()
both point to the same memory address? Is this something to do with overriding the __repr__
method of Bar
?
2). Did the way I asked Q1 above make sense (trying to get better at CS terminology)?