As a general rule, classes are better at “memory” like this because they make the state
retention explicit in attributes. Short of using classes, though, globals, enclosing scope
references like these, and default arguments are the main ways that Python functions
can retain state information. To see how they compete, Chapter 18 provides complete
coverage of defaults, but the next section gives enough of an introduction to get us
started.