Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7524297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:03:40+00:00 2026-05-30T03:03:40+00:00

According to the python tutorial , functions look for variable names in the symbol

  • 0

According to the python tutorial, functions look for variable names in the symbol tables of enclosing functions before looking for global functions:

The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced.

What exactly does “enclosing function” mean, and when is it used?

I see the following code prints 10 when called

def parent_function():
    y=10
    def child_function():
        print y
    child_function()

However, calling child_function() alone produces an error. Are enclosing functions used frequently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:03:43+00:00Added an answer on May 30, 2026 at 3:03 am

    The concept of an enclosing function is key in understanding the idea of closures. Because python does not have fully featured lambdas (they only allow expressions and not statements), having nested functions to pass on to other functions is a common use case:

    def receiving_function(f):
        f()
    
    def parent_function():
        y = 10
    
        def child_function():
            print(y)
    
        receiving_function(child_function)
    

    will print 10 as before. This is a common instance of a closure, where the enclosing function “hands off” it’s variables to the enclosed function. In the example above, this function is passed off to the receiving_function along with the non-local variable y.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode the result of the Python os.wait() function. This returns, according
I am new to python and graphics but have programmed before. According to http://en.wikipedia.org/wiki/Transformation_matrix#Rotation
Let's say I have a function in Python like so: def foo(x): pass According
According to the Python 2.6.5 docs [1], the bsddb module has been deprecated for
What exactly do *args and **kwargs mean? According to the Python documentation, from what
So according to the Zen of Python ... Explicit is better than implicit ...
According to Jython's documentation : Jython is an implementation of the Python language for
I am trying to overload operators of a C++ class using Boost.Python. According to
According to my interpretation of Python 2.7.2 documentation for Built-In Types 5.7 Set Types
I am a newbie to Python and would like to genereate some numbers according

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.