I would like to know, if there is a way to overload operators in Python in runtime. For instance:
class A:
pass
a = A()
a.__str__ = lambda self: "noice"
print(str(a))
The desired output is "noice"
, but the given code uses object
's implementation of the str
function instead, yielding something along the lines: <__main__.A object at 0x000001CAB2051490>
.
Why doesn't the code use my overriden implementation of the function overload?
Python version used is 3.9.2
.