Could someone please paraphrase this statement about variables andfunctions in Python?

J

jsrig88

Could someone please paraphrase this statement about variables and functions in Python?

I am going through the tutorials on docs.python.org, and I came across thisexcerpt from http://docs.python.org/3/tutorial/controlflow.html:

"The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in afunction store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tablesof 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), althoughthey may be referenced.

"The actual parameters (arguments) to a function call are introduced in thelocal symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). [1] When a function calls another function, a new local symbol table is created for that call."

Even as a professional programmer, I'm not really able to follow this. It appears to be self-contradictory, amgiguous, incomplete, and possessive of logical missteps. The problem with looking for this information elsewhere is that it's not going to be all in one spot like this half the time, and it's not going to be readily searchable on Google without more knowledge of what it's referring to. However this looks like something that's too important to overlook.

I can tell it's referring to things like scope, pass-by-value, references, probably the call stack, etc., but it is written extremely poorly. Translation please? Thanks!
 
J

Joel Goldstick

Could someone please paraphrase this statement about variables and functions in Python?

I am going through the tutorials on docs.python.org, and I came across this excerpt from http://docs.python.org/3/tutorial/controlflow.html:

"The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments ina 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.

"The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). [1] When a function calls another function, a new local symbol table is created for that call."

Even as a professional programmer, I'm not really able to follow this. It appears to be self-contradictory, amgiguous, incomplete, and possessive of logical missteps. The problem with looking for this information elsewhere is that it's not going to be all in one spot like this half the time, andit's not going to be readily searchable on Google without more knowledge of what it's referring to. However this looks like something that's too important to overlook.

I can tell it's referring to things like scope, pass-by-value, references, probably the call stack, etc., but it is written extremely poorly. Translation please? Thanks!

Nearly everyone gets confused by this initially. You should google
python namespaces
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top