Kaydet (Commit) c113465a authored tarafından Tim Peters's avatar Tim Peters

SF non-bug 123520: fleshed out the tutorial's lambda example a little more.

üst cb54be86
...@@ -1497,8 +1497,15 @@ cannot reference variables from the containing scope, but this can be ...@@ -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}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment