Browse Source

Closure

pull/10/head
Jure Šorn 6 years ago
parent
commit
2b11ea9298
1 changed files with 6 additions and 0 deletions
  1. 6
      README.md

6
README.md

@ -536,6 +536,10 @@ creature = Creature()
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.
```python
def get_multiplier(a):
def out(b):
@ -549,6 +553,8 @@ def get_multiplier(a):
30
```
* **If multiple nested functions within enclosing function reference the same value, that value gets shared.**
#### Or:
```python
from functools import partial

Loading…
Cancel
Save