Python - Name


Language - Name (Program Entity) in Python

Names (refer to|are pointer for) objects.

Names are introduced by name binding operations such as during the def process.

Binding operations


  • targets that are identifiers if occurring in an assignment, for loop header, or after as in a with statement or except clause.
  • formal parameters to functions,

class definitions

class (these bind the class or name in the defining block)

function definitions

function definitions (these bind the function name in the defining block)


The import statement .

The import statement of the form from … import * binds all names defined in the imported module, except those beginning with an underscore. This form may only be used at the module level.


Python - Name Scope

  • If a name is bound in a block, it is a local variable of that block, unless declared as nonlocal or global.
  • If a name is bound at the module level, it is a global variable. (The variables of the module code block are local and global.)
  • If a variable is used in a code block but not defined there, it is a free variable.


When a name is not found at all, a NameError exception is raised.

Documentation / Reference

Powered by ComboStrap