When Closure get external variable's value?

Huayang Xia huayang.xia at gmail.com
Mon Dec 18 15:22:13 EST 2006


What will the following piece of code print? (10 or 15)

        def testClosure(maxIndex) :

            def closureTest():
                return maxIndex

            maxIndex += 5

            return closureTest()

        print testClosure(10)

My question is when the closure function gets value for maxindex? Run
time or compile time?

Thanks.




More information about the Python-list mailing list