Created
April 10, 2013 03:15
-
-
Save zenloner/5351470 to your computer and use it in GitHub Desktop.
factory function implemented with nested scope
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
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