Skip to content

Instantly share code, notes, and snippets.

@dketov
Created December 13, 2011 14:28
Show Gist options
  • Save dketov/1472301 to your computer and use it in GitHub Desktop.
Save dketov/1472301 to your computer and use it in GitHub Desktop.
Вложенные определения функций
# -*- 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