|
|
@ -538,7 +538,7 @@ Closure |
|
|
|
------- |
|
|
|
**We have a closure in Python when:** |
|
|
|
* **A nested function references a value of its enclosing function, and then** |
|
|
|
* **the enclosing function returns the nested function. |
|
|
|
* **the enclosing function returns the nested function.** |
|
|
|
|
|
|
|
```python |
|
|
|
def get_multiplier(a): |
|
|
@ -554,6 +554,7 @@ def get_multiplier(a): |
|
|
|
``` |
|
|
|
|
|
|
|
* **If multiple nested functions within enclosing function reference the same value, that value gets shared.** |
|
|
|
* **To dynamicaly acces functions first free variable use `'<function>.__closure__[0].cell_contents`'.** |
|
|
|
|
|
|
|
#### Or: |
|
|
|
```python |
|
|
|