#Decorator shelf # @timer is equivalent to test=timer (test0 import time def timer(func): def wrapper(): starttime=time.time() func() # is running test() stoptime= time.time() print ( ' running time %s ' %(stoptime- starttime)) # print(func) return wrapper @timer #equivalent to test=timer(test) , a decorator name is enough, you can directly call def test(): time.sleep( 3 ) print ( ' The test function finished running ' ) res =timer(test) #wrapper () address when returned res() #wrapper () when executed