In Python you can override an operation for your class (say, addition) by defining __add__. This will make it possible add class instance with other values/instances, but you can’t add built-ins to instances:
foo = Foo()
bar = foo + 6 # Works
bar = 6 + foo # TypeError: unsupported operand type(s) for +: 'int' and 'Foo'
Is there any way to make enable this?
You have to define the method
__radd__(self, other)to override the operator+when your instance is on the right side.