Skip to content

Commit

Permalink
Merge pull request satwikkansal#247 from abdnh/patch-1
Browse files Browse the repository at this point in the history
Fix typo
  • Loading branch information
satwikkansal authored Feb 3, 2021
2 parents 048a620 + de4b851 commit 48256e1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ The values of `x` were different in every iteration prior to appending `some_fun
* When defining a function inside a loop that uses the loop variable in its body, the loop function's closure is bound to the *variable*, not its *value*. The function looks up `x` in the surrounding context, rather than using the value of `x` at the time the function is created. So all of the functions use the latest value assigned to the variable for computation. We can see that it's using the `x` from the surrounding context (i.e. *not* a local variable) with:
```py
>>> import inspect
>>> inspect.getclosurevals(funcs[0])
>>> inspect.getclosurevars(funcs[0])
ClosureVars(nonlocals={}, globals={'x': 6}, builtins={}, unbound=set())
```
Since `x` is a global value, we can change the value that the `funcs` will lookup and return by updating `x`:
Expand Down

0 comments on commit 48256e1

Please sign in to comment.