Python - Name

> Procedural Languages > Python > Python - Grammar (Package | Module)

1 - About

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.

Advertising

3 - Binding operations

3.1 - identifiers

  • 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,

3.2 - class definitions

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

3.3 - function definitions

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

3.4 - Import

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.

4 - Scope

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.
Advertising

5 - NameError

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

6 - Documentation / Reference

lang/python/grammar/name.txt · Last modified: 2019/02/18 12:33 by gerardnico