Created
June 13, 2018 16:20
-
-
Save msoedov/325a23309424fb45419908b4e8c7bf62 to your computer and use it in GitHub Desktop.
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 wrapper3(): | |
v = dict(counter=0) | |
def incr(): | |
v['counter'] += 1 | |
return v['counter'] | |
return incr | |
fn = wrapper3() | |
print(fn()) | |
# >> 1 |
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 wrapper4(): | |
class Vars: | |
counter = 0 | |
def incr(): | |
Vars.counter += 1 | |
return Vars.counter | |
return incr | |
fn = wrapper4() | |
print(fn()) | |
# >> 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment