class myFloat1(float):
def __add__(self, value):
if type(value) is str:
return self.__class__(float(self) + float(value))
else:
return self.__class__(float(self) + value)
def __radd__(self, value):
return self.__add__(value)
class myFloat2(float):
pass
class myFloat3(myFloat1):
def __radd__(self, value):
return self.__add__(value + 10000)
x = myFloat1(1.0)
y = myFloat2(2.0)
z = myFloat3(3.0)
o, p, q = '4.0' + x + y + '5.0', y + x, x + z
print(o, type(o))
print(p, type(p))
print(q, type(q))
Y2xhc3MgbXlGbG9hdDEoZmxvYXQpOgogICAgZGVmIF9fYWRkX18oc2VsZiwgdmFsdWUpOgogICAgICAgIGlmIHR5cGUodmFsdWUpIGlzIHN0cjoKICAgICAgICAgICAgcmV0dXJuIHNlbGYuX19jbGFzc19fKGZsb2F0KHNlbGYpICsgZmxvYXQodmFsdWUpKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJldHVybiBzZWxmLl9fY2xhc3NfXyhmbG9hdChzZWxmKSArIHZhbHVlKQogCiAgICBkZWYgX19yYWRkX18oc2VsZiwgdmFsdWUpOgogICAgICAgIHJldHVybiBzZWxmLl9fYWRkX18odmFsdWUpCgpjbGFzcyBteUZsb2F0MihmbG9hdCk6CiAgICBwYXNzCiAgICAgICAKY2xhc3MgbXlGbG9hdDMobXlGbG9hdDEpOgogICAgZGVmIF9fcmFkZF9fKHNlbGYsIHZhbHVlKToKICAgICAgICByZXR1cm4gc2VsZi5fX2FkZF9fKHZhbHVlICsgMTAwMDApCiAgICAKeCA9IG15RmxvYXQxKDEuMCkKeSA9IG15RmxvYXQyKDIuMCkKeiA9IG15RmxvYXQzKDMuMCkKbywgcCwgcSA9ICc0LjAnICsgeCArIHkgKyAnNS4wJywgeSArIHgsIHggKyB6CnByaW50KG8sIHR5cGUobykpCnByaW50KHAsIHR5cGUocCkpCnByaW50KHEsIHR5cGUocSkpCg==