Decorators

Run Settings
LanguagePython
Language Version
Run Command
print('decorator sample1') def counter(fn): count = 0 def inner(*args, **kwargs): nonlocal count count += 1 print('Function {0} was called {1} times'.format(fn.__name__,count)) return fn(*args, **kwargs) return inner def add(a,b=0): return a + b print(id(add)) add = counter(add) print(id(add)) add(1,1) add(2,2) print('decorator sample2') def counter(fn): count = 0 def inner(*args, **kwargs): nonlocal count count += 1 print('Function {0} was called {1} times'.format(fn.__name__,count)) return fn(*args, **kwargs) return inner def add(a,b=0): return a + b print(id(add)) add(1,1) add(2,2)
Editor Settings
Theme
Key bindings
Full width
Lines