# Decoration ###### tags: `python` `hijack` > [name=Jason Lin] ## Decorator ```python= @hijack def add(x,y): return x+y @hijack def mul(x,y): return x*y ``` ## How Does the Interpreter Handle '@*decorator*'? - Since running the program, it interpretes '@*decorator*' as '*func* = *decorator*(*func*)' (even if you don't call *func*) - In other words, it refers *func* as *decorator*'s first positional parameter, then paste the *func* memo on the returned value of *decorator*(*func*) ### (Simulate) A decorator with parameters: ```python= def decowithparam(v=False): def deco(f): def decoo(*p,*pp): ... return decoo return deco @decowithparam(False) def add(...): ... @decowithparam(True) def mul(...): ... ```