Python decorator
Run this file, and there is output:
The two functions are not called and there is supposed to have no output.
But when Python compiler finds the decorator "@", these steps are executed:
call function test, the input parameter for test is the function named "func"
test function is being executed
What you're doing is calling test
, then using the result of that call to decorate func
. Therefore runs immediately.
Last updated