O'Reilly logo

Python Essentials by Steven F. Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with namespaces

When a function is evaluated, Python creates a local namespace. The parameter variables are created in this local namespace when the argument values (or default values) are assigned. Any variables that are created in the suite of statements in the function's body are also created in this local namespace.

As we noted in Chapter 4, Variables, Assignment and Scoping Rules, each object has a reference counter. An object provided as an argument to a function will have the reference count incremented during the execution of the function's suite of statements.

When the function finishes—either because of an explicit return statement or the implicit return at the end of the suite—the namespace is removed. This will decrement the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required