The Python Handbook
arguments from the command line 30. Lambda Functions 31. Recursion 32. Nested Functions 33. Closures 34. Decorators 35. Docstrings 36. Introspection 37. Annotations 38. Exceptions 39. The with functionality that's local to a function, and not useful elsewhere. Also, because we can make use of closures (more on this later). Here is an example: def talk(phrase): def say(word): print(word) print(count) increment() count() This is useful especially with closures, as we'll see later. 33. Closures 75 If you return a nested function from a function, that nested function has0 码力 | 93 页 | 7.31 MB | 1 年前3
Mypy 1.8.0 Documentation1.29.20 Narrowing and inner functions Because closures in Python are late-binding (https://docs.python-guide.org/writing/gotchas/#late-binding-closures), mypy will not narrow the type of a captured variable0 码力 | 234 页 | 902.89 KB | 1 年前3
Mypy 1.10.0+dev Documentationblock. Narrowing and inner functions Because closures in Python are late-binding (https://docs.python- guide.org/writing/gotchas/#late-binding-closures), mypy will not narrow the type of a captured variable0 码力 | 318 页 | 270.84 KB | 1 年前3
Mypy 1.8.0 Documentationblock. Narrowing and inner functions Because closures in Python are late-binding (https://docs.python- guide.org/writing/gotchas/#late-binding-closures), mypy will not narrow the type of a captured variable0 码力 | 318 页 | 271.55 KB | 1 年前3
Mypy 1.10.0+dev Documentation1.29.20 Narrowing and inner functions Because closures in Python are late-binding (https://docs.python-guide.org/writing/gotchas/#late-binding-closures), mypy will not narrow the type of a captured variable0 码力 | 234 页 | 913.89 KB | 1 年前3
PyWebIO v1.2.3 Documentationcounter'], [partial(add, cnt), partial(show, ˓→ cnt)]) hold() Of course, you can also use function closures to achieved the same: def main(): cnt = 0 def add(): nonlocal cnt cnt += 1 def show(): put_text(cnt)0 码力 | 92 页 | 1.32 MB | 1 年前3
PyWebIO v1.2.2 Documentationcounter'], [partial(add, cnt), partial(show, ˓→ cnt)]) hold() Of course, you can also use function closures to achieved the same: def main(): cnt = 0 def add(): nonlocal cnt cnt += 1 def show(): put_text(cnt)0 码力 | 92 页 | 1.35 MB | 1 年前3
PyWebIO v1.3.3 Documentationcounter'], [partial(add, cnt), partial(show, ˓→ cnt)]) hold() Of course, you can also use function closures to achieved the same: def main(): cnt = 0 def add(): nonlocal cnt cnt += 1 def show(): put_text(cnt)0 码力 | 100 页 | 1.34 MB | 1 年前3
PyWebIO v1.3.1 Documentationcounter'], [partial(add, cnt), partial(show, ˓→ cnt)]) hold() Of course, you can also use function closures to achieved the same: def main(): cnt = 0 def add(): nonlocal cnt cnt += 1 def show(): put_text(cnt)0 码力 | 100 页 | 1.34 MB | 1 年前3
PyWebIO v1.3.0 Documentationcounter'], [partial(add, cnt), partial(show, ˓→ cnt)]) hold() Of course, you can also use function closures to achieved the same: def main(): cnt = 0 def add(): nonlocal cnt cnt += 1 def show(): put_text(cnt)0 码力 | 100 页 | 1.34 MB | 1 年前3
共 54 条
- 1
- 2
- 3
- 4
- 5
- 6













