The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Python name binding, assignments and import statements, scope (global vs local) Python 3.11
By Guest on 2nd November 2022 08:12:43 AM | Syntax: TEXT | Views: 205



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. 4.2.1. Binding of names
  2. -----------------------
  3.  
  4. *Names* refer to objects.  Names are introduced by name binding
  5. operations.
  6.  
  7. The following constructs bind names:
  8.  
  9. * formal parameters to functions,
  10.  
  11. * class definitions,
  12.  
  13. * function definitions,
  14.  
  15. * assignment expressions,
  16.  
  17. * targets that are identifiers if occurring in an assignment:
  18.  
  19.   * "for" loop header,
  20.  
  21.   * after "as" in a "with" statement, "except" clause, "except*"
  22.     clause, or in the as-pattern in structural pattern matching,
  23.  
  24.   * in a capture pattern in structural pattern matching
  25.  
  26. * "import" statements.
  27.  
  28. The "import" statement of the form "from ... import *" binds all names
  29. defined in the imported module, except those beginning with an
  30. underscore. This form may only be used at the module level.
  31.  
  32. A target occurring in a "del" statement is also considered bound for
  33. this purpose (though the actual semantics are to unbind the name).
  34.  
  35. Each assignment or import statement occurs within a block defined by a
  36. class or function definition or at the module level (the top-level
  37. code block).
  38.  
  39. If a name is bound in a block, it is a local variable of that block,
  40. unless declared as "nonlocal" or "global".  If a name is bound at the
  41. module level, it is a global variable.  (The variables of the module
  42. code block are local and global.)  If a variable is used in a code
  43. block but not defined there, it is a *free variable*.
  44.  
  45. Each occurrence of a name in the program text refers to the *binding*
  46. of that name established by the following name resolution rules.
  47.  
  48. See also:
  49. Python Classes and Objects >> Python Binding a Name to an Object
















Python software and documentation are licensed under the PSF License Agreement.
Starting with Python 3.8.6, examples, recipes, and other code in the documentation are dual licensed under the PSF License Agreement and the Zero-Clause BSD license.
Some software incorporated into Python is under different licenses. The licenses are listed with code falling under that license. See Licenses and Acknowledgements for Incorporated Software for an incomplete list of these licenses.

Python and it's documentation is:
Copyright © 2001-2022 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com. All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.

See History and License for complete license and permissions information:
https://docs.python.org/3/license.html#psf-license
  • Recent Pastes