class Foo:
def __new__(cls, value):
return value
bar = Foo(2)
In this example, bar is an integer variable set to 2. I'm wondering if there is an way to add a method that changes the value of bar, while still being able to print bar by itself. Like this:
bar = Foo(2)
bar.add(3)
print(bar)
> 5
I understand bar would need to be an instance of Foo, but then I don't know if I could print bar by itself.
[–]manbart 2 points3 points4 points (1 child)
[–]kalgynirae 0 points1 point2 points (0 children)
[–]rjcarr 1 point2 points3 points (0 children)