fork download
  1. class Example:
  2. def __init__(self, number):
  3. self.number = number
  4.  
  5. def __add__(self, other):
  6. return Example(self.number + other.number)
  7.  
  8. def __sub__(self, other):
  9. return self.number - other.number
  10.  
  11. def doSmth(self):
  12. print(self.number)
  13.  
  14. a = Example(7)
  15. b = Example(42)
  16.  
  17. c = a + b
  18. d = a - b
  19.  
  20. c.doSmth()
  21. d.doSmth()
Runtime error #stdin #stdout #stderr 0.14s 23704KB
stdin
Standard input is empty
stdout
49
stderr
Traceback (most recent call last):
  File "./prog.py", line 21, in <module>
AttributeError: 'int' object has no attribute 'doSmth'