|
@ -489,19 +489,18 @@ creature = Creature() |
|
|
Closure |
|
|
Closure |
|
|
------- |
|
|
------- |
|
|
```python |
|
|
```python |
|
|
def multiply_closure(a): |
|
|
|
|
|
|
|
|
def get_multiplier(a): |
|
|
def out(b): |
|
|
def out(b): |
|
|
return a * b |
|
|
return a * b |
|
|
return out |
|
|
return out |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
```python |
|
|
```python |
|
|
>>> multiply_by_3 = multiply_closure(3) |
|
|
|
|
|
|
|
|
>>> multiply_by_3 = get_multiplier(3) |
|
|
>>> multiply_by_3(10) |
|
|
>>> multiply_by_3(10) |
|
|
30 |
|
|
30 |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### Or: |
|
|
#### Or: |
|
|
```python |
|
|
```python |
|
|
from functools import partial |
|
|
from functools import partial |
|
|