Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class XFunction():
- def __call__(self, *args):
- return self.f(*args)
- def __mul__(self, number):
- def new_f(*args):
- return number*self.f(*args)
- return XFunction(new_f)
- def __rmul__(self, number):
- return self.__mul__(number)
- def __init__(self, f):
- self.f = f
- if __name__ == "__main__":
- xfunc = XFunction(lambda x: x)
- assert xfunc(1)==1
- yfunc = 2*xfunc
- assert yfunc(1) ==2
Add Comment
Please, Sign In to add comment