fork(1) download
  1. class myFloat1(float):
  2. def __add__(self, value):
  3. if type(value) is str:
  4. return self.__class__(float(self) + float(value))
  5. else:
  6. return self.__class__(float(self) + value)
  7.  
  8. def __radd__(self, value):
  9. return self.__add__(value)
  10.  
  11. class myFloat2(float):
  12. pass
  13.  
  14. class myFloat3(myFloat1):
  15. def __radd__(self, value):
  16. return self.__add__(value + 10000)
  17.  
  18. x = myFloat1(1.0)
  19. y = myFloat2(2.0)
  20. z = myFloat3(3.0)
  21. o, p, q = '4.0' + x + y + '5.0', y + x, x + z
  22. print(o, type(o))
  23. print(p, type(p))
  24. print(q, type(q))
  25.  
Success #stdin #stdout 0.09s 10088KB
stdin
Standard input is empty
stdout
12.0 <class '__main__.myFloat1'>
3.0 <class 'float'>
10004.0 <class '__main__.myFloat3'>