diff options
author | Fred Drake <fdrake@acm.org> | 2001-09-06 18:21:30 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-09-06 18:21:30 (GMT) |
commit | 8b09f4985ce02d4ae8dc63b67e498293488f0dca (patch) | |
tree | 19225bc3abd3f7a4830564d8b60a09cca280ab41 /Doc | |
parent | 9c75ff785a328a155f17428b508b0e501d6c4a05 (diff) | |
download | cpython-8b09f4985ce02d4ae8dc63b67e498293488f0dca.zip cpython-8b09f4985ce02d4ae8dc63b67e498293488f0dca.tar.gz cpython-8b09f4985ce02d4ae8dc63b67e498293488f0dca.tar.bz2 |
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.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/tut/tut.tex | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index 00d0695..e851ea6 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -1353,7 +1353,10 @@ in the \emph{defining} scope, so that \begin{verbatim} i = 5 -def f(arg = i): print arg + +def f(arg=i): + print arg + i = 6 f() \end{verbatim} @@ -1366,9 +1369,10 @@ list or dictionary. For example, the following function accumulates the arguments passed to it on subsequent calls: \begin{verbatim} -def f(a, l = []): - l.append(a) - return l +def f(a, L=[]): + L.append(a) + return L + print f(1) print f(2) 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: \begin{verbatim} -def f(a, l = None): - if l is None: - l = [] - l.append(a) - return l +def f(a, L=None): + if L is None: + L = [] + L.append(a) + return L \end{verbatim} \subsection{Keyword Arguments \label{keywordArgs}} |