No, there is no language support for creating block scope.
The following constructs create scope:
- module
- class
- function (incl. lambda)
- generator expression
- comprehensions (dict, set, list(in Python 3.x))
More Related Contents:
- Short description of the scoping rules?
- UnboundLocalError on local variable when reassigned after first use
- Don’t understand why UnboundLocalError occurs (closure) [duplicate]
- Scoping in Python ‘for’ loops
- Scope of python variable in for loop
- How do I create a list of lambdas (in a list comprehension/for loop)?
- Explaining the ‘self’ variable to a beginner [duplicate]
- How to access outer class from an inner class?
- Why does this UnboundLocalError occur (closure)? [duplicate]
- How can I change a global variable from within a function?
- Why does assigning to my global variables not work in Python?
- Nested classes’ scope?
- Python nested functions variable scoping [duplicate]
- Python scope: “UnboundLocalError: local variable ‘c’ referenced before assignment” [duplicate]
- How do I pass variables across functions?
- Python: load variables in a dict into namespace
- Python overwriting variables in nested functions [duplicate]
- Advanced Nested List Comprehension Syntax
- How to create module-wide variables in Python? [duplicate]
- String with ‘f’ prefix in python-3.6
- How can a function access its own attributes?
- globals and locals in python exec()
- Does filehandle get closed automatically in Python after it goes out of scope?
- Nested list comprehension scope
- Global dictionaries don’t need keyword global to modify them? [duplicate]
- UnboundLocalError trying to use a variable (supposed to be global) that is (re)assigned (even after first use)
- How do the scoping rules work with classes?
- Python global variable scoping
- Why can functions in Python print variables in enclosing scope but cannot use them in assignment? [duplicate]
- Scope of variable within “with” statement?