Skip to content

Instantly share code, notes, and snippets.

@lemonad
Created March 4, 2020 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemonad/f88887a1d12a4bdc74e6677f395d27c8 to your computer and use it in GitHub Desktop.
Save lemonad/f88887a1d12a4bdc74e6677f395d27c8 to your computer and use it in GitHub Desktop.
Function instead of class with closure?
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