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