class_number.py 266 B

123456789101112131415
  1. # test class with __add__ and __sub__ methods
  2. class C:
  3. def __init__(self, value):
  4. self.value = value
  5. def __add__(self, rhs):
  6. print(self.value, '+', rhs)
  7. def __sub__(self, rhs):
  8. print(self.value, '-', rhs)
  9. c = C(0)
  10. c + 1
  11. c - 2