O'Reilly logo
  • Chris Kang thinks this is interesting:

In addition to its predefined attributes, a function object may have other arbitrary attributes. To create an attribute of a function object, bind a value to the appropriate attribute reference in an assignment statement after the def statement executes. For example, a function could count how many times it gets called:

def counter():
    counter.count += 1
    return counter.count


Cover of Python in a Nutshell, 3rd Edition


consider "count" as a member variable that is accessible through the function reference.