mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
SF non-bug 123520: fleshed out the tutorial's lambda example a little more.
This commit is contained in:
parent
cb54be869c
commit
c113465a49
1 changed files with 9 additions and 2 deletions
|
@ -1497,8 +1497,15 @@ cannot reference variables from the containing scope, but this can be
|
||||||
overcome through the judicious use of default argument values, e.g.
|
overcome through the judicious use of default argument values, e.g.
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
def make_incrementor(n):
|
>>> def make_incrementor(n):
|
||||||
return lambda x, incr=n: x+incr
|
... return lambda x, incr=n: x+incr
|
||||||
|
...
|
||||||
|
>>> f = make_incrementor(42)
|
||||||
|
>>> f(0)
|
||||||
|
42
|
||||||
|
>>> f(1)
|
||||||
|
43
|
||||||
|
>>>
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue