About 223,000 results
Open links in new tab
  1. python - Short description of the scoping rules - Stack Overflow

    Nov 15, 2008 · Actually, a concise rule for Python Scope resolution, from Learning Python, 3rd. Ed.. (These rules are specific to variable names, not attributes. If you reference it without a …

  2. Python nested functions variable scoping - Stack Overflow

    Mar 7, 2011 · In Python 3, you can use the nonlocal statement to access non-local, non-global scopes. The nonlocal statement causes a variable definition to bind to a previously created …

  3. python - What's the scope of a variable initialized in an if …

    537 Python variables are scoped to the innermost function, class, or module in which they're assigned. Control blocks like if and while blocks don't count, so a variable assigned inside an if …

  4. Block scope in Python - Stack Overflow

    Python creates a new scope for each module, class, function, generator expression, dict comprehension, set comprehension and in Python 3.x also for each list comprehension.

  5. python - Variables declared outside function - Stack Overflow

    In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a value anywhere within the function’s body, it’s assumed to be local unless explicitly …

  6. Is it possible to modify a variable in python that is in an outer ...

    Python implements lexical, not dynamic scope - like almost all modern languages. The techniques here will not allow access to the caller's variables - unless the caller also happens to be an …

  7. python - How to inject variable into scope with a decorator?

    Jul 25, 2013 · 73 [Disclaimer: there may be more pythonic ways of doing what I want to do, but I want to know how python's scoping works here] I'm trying to find a way to make a decorator …

  8. python - Scope of lambda functions and their parameters

    Jun 2, 2009 · Python does uses references of course, but it does not matter in this context. When you define a lambda (or a function, since this is the exact same behavior), it does not evaluate …

  9. python - How can I change a global variable from within a …

    The scope of the variable is local to the block unless defined explicitly using keyword global. There is another way to access the global variable local to a function using the globals function:

  10. What is the Python equivalent of static variables inside a function ...

    Nov 11, 2008 · In the example below (python 3.5 or greater to use the "f"), the counter variable is defined outside of the function. Defining it as global in the function signifies that the "global" …