I am trying to add a class object with a number, but I\'m confused on how to go about adding a class object with two numbers. For example, this is my hypothetical ad
You would want your return value to be an object itself, that also supports the add operation, e.g.:
class A: def __init__(self, value=0): self.value = value def __add__(self, b): return A(self.value + b) def __str__(self): return str(self.value) a = A() print(a + 1 + 2)
Output:
3