1
0
mirror of https://github.com/satwikkansal/wtfpython synced 2024-11-24 20:14:23 +01:00

Merge pull request #247 from abdnh/patch-1

Fix typo
This commit is contained in:
Satwik Kansal 2021-02-03 07:24:33 +00:00 committed by GitHub
commit 48256e1fe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
README.md vendored
View File

@ -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`: