class PrintFuncNum:
def __init__(self, func):
self.func = func
def check(self, test):
answer = self.func(test)
test1 = PrintFuncNum(func)
# You can put test*3 in the answer in the check part
# Or I would like to add +3 or create a class by the user's designation.
As above, I would like to create an instance by making a func factor from the code I want.
Is there a way?
Please refer to the code below.
class PrintFuncNum:
def __init__(self, func):
self.func = func
self.answer = 10
def check(self, test):
self.answer = self.func(self.answer, test)
print(self.answer)
def add(a,b):
return a+b
def multiply(a,b):
return a*b
test1 = PrintFuncNum(add)
test1.check(3)
test2 = PrintFuncNum(multiply)
test2.check(3)
© 2024 OneMinuteCode. All rights reserved.