Skip to content

Instantly share code, notes, and snippets.

@zenloner
Created April 10, 2013 03:15
Show Gist options
  • Save zenloner/5351470 to your computer and use it in GitHub Desktop.
Save zenloner/5351470 to your computer and use it in GitHub Desktop.
factory function implemented with nested scope
def maker(N):
'''
if you want to get different functions
when you pass different parameters into a maker,
you can use nested scope function,
it's also known as a factory function.
'''
def action(X):
return X**N
return action
f = maker(2)
f(3) #print 9
f = maker(3)
f(3) #print 27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment