Created
December 13, 2011 14:28
-
-
Save dketov/1472301 to your computer and use it in GitHub Desktop.
Вложенные определения функций
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Вложенные определения функций | |
""" | |
def f1(): | |
x = 88 | |
def f2(x=x): | |
print x | |
f2() | |
f1() # prints 88 | |
def f1(): | |
x = 99 | |
def f2(): | |
def f3(): | |
print x | |
f3() | |
f2() | |
f1() | |
def func(): | |
x = 4 | |
action = (lambda n: x ** n) # x in enclosing def | |
return action | |
x = func() | |
print x(2) # prints 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment