I am not sure if this is posible in Python: suppose I have a function such as
def is_even(x) :
if type(x) == int :
return mx % 2 == 0
else :
return NotImplemented
Suppose I want to extend it to a different class, say fractions, I would like to be able to redefine is_even for fractions without knowing for which other types it is defined, something like:
def is_even(x) :
if type(x) == Fraction :
return x.numerator % 2 == 0
else :
return the other is_even(x)
Again I want to define it for many types without knowing for which other types it might be already defined (if any).