4 ms·
You can mutate closed-over variables in Python. Here's an example.... def some_function(val): def say_stuff(): print("message is: {}".format(val)
by pcote 11y ago
You can mutate closed-over variables in Python. Here's an example....
def some_function(val):
def say_stuff():
print("message is: {}".format(val))
def mutate_me(new_mutation):
nonlocal val
val = new_mutation
say_stuff.mutate_me = mutate_me
return say_stuff
if __name__ == '__main__':
f = some_function("hello")
f.mutate_me("goodbye")
f()