let me simplify my question on scope of vars

Terry Reedy tjreedy at udel.edu
Fri Dec 22 21:37:00 EST 2006


"Pyenos" <pyenos at pyenos.org> wrote in message 
news:877iwjcttj.fsf at pyenos.pyenos.org...
| "code"
| var=1
| class CLASS:
|        def METHOD1:
|                def METHOD2:
|                        var+=var
|                return var
|                METHOD2()       #line8
|        return var
| METHOD1()                       #line10
| "end code"
|
| Q1: does class CLASS inherit var=0 from line1?
| Q2: does def METHOD1 inherit var=0 from line1?
| Q3: does def METHOD2 inherit var=0 from line1?
| Q3: does line8 return '2'?
| Q4: does line10 return '2\n2'?

You should find the answers yourself using the interactive interpreter or 
IDLE .
This is the most valuable answer I can give you.

tjr






More information about the Python-list mailing list