First page Back Continue Last page Overview Graphics

Functions with Attributes

Functions can be attributed as well.

They can used as a substitute for the non-existing statical variables:

def f(x):

f.counter = getattr(f, "counter", 0) + 1

return "Monty Python"

for i in range(10):

f(i)

print(f.counter)