Created
March 4, 2020 23:11
-
-
Save lemonad/f88887a1d12a4bdc74e6677f395d27c8 to your computer and use it in GitHub Desktop.
Function instead of class with closure?
This file contains 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 S(x): | |
def printx(): | |
print(x) | |
def times_x(multiplier): | |
return multiplier * x | |
def change_x(new_x): | |
nonlocal x | |
x = new_x | |
S.printx = printx | |
S.times_x = times_x | |
S.change_x = change_x | |
return S |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment