class fruits():
def apple(self,name):
print(" I am a %s"%(name))
def method(self,name,func):
return func(name)
def main(self):
return self.method(" Red apple ",self.apple)
fruits().main()
The key lies in method()
Method func()
It is already instantiated , So we can't add self
from datetime import datetime
class fruits():
def method(f):
def x(self,*args,**kwargs):
print(datetime.now())
f(self,*args,**kwargs)
return;
return x
@method
def apple(self,name):
print(" I am a %s"%(name))
fruits().apple(" green apple ")
Jane Medium : Tested the effec
One 、 Concepts of classes and