Make the examples for "Default Argument Values" more presentable and
less hostile to newbie use at the interactive prompt. This is in response to SF bug #458654.
This commit is contained in:
parent
9c75ff785a
commit
8b09f4985c
|
@ -1353,7 +1353,10 @@ in the \emph{defining} scope, so that
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
i = 5
|
i = 5
|
||||||
def f(arg = i): print arg
|
|
||||||
|
def f(arg=i):
|
||||||
|
print arg
|
||||||
|
|
||||||
i = 6
|
i = 6
|
||||||
f()
|
f()
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
@ -1366,9 +1369,10 @@ list or dictionary. For example, the following function accumulates
|
||||||
the arguments passed to it on subsequent calls:
|
the arguments passed to it on subsequent calls:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
def f(a, l = []):
|
def f(a, L=[]):
|
||||||
l.append(a)
|
L.append(a)
|
||||||
return l
|
return L
|
||||||
|
|
||||||
print f(1)
|
print f(1)
|
||||||
print f(2)
|
print f(2)
|
||||||
print f(3)
|
print f(3)
|
||||||
|
@ -1386,11 +1390,11 @@ If you don't want the default to be shared between subsequent calls,
|
||||||
you can write the function like this instead:
|
you can write the function like this instead:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
def f(a, l = None):
|
def f(a, L=None):
|
||||||
if l is None:
|
if L is None:
|
||||||
l = []
|
L = []
|
||||||
l.append(a)
|
L.append(a)
|
||||||
return l
|
return L
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
\subsection{Keyword Arguments \label{keywordArgs}}
|
\subsection{Keyword Arguments \label{keywordArgs}}
|
||||||
|
|
Loading…
Reference in New Issue