diff options
author | Fred Drake <fdrake@acm.org> | 1999-06-30 15:32:50 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 1999-06-30 15:32:50 (GMT) |
commit | f1ad207f2ab67d76c062c342b2832ae3f0d638bd (patch) | |
tree | 6b2b905ce17f81ff563e0d2d0e0a7f2915ab79b5 /Doc/tut/tut.tex | |
parent | 3d0971e33e81538862cd71425d97c3cfea5e3c00 (diff) | |
download | cpython-f1ad207f2ab67d76c062c342b2832ae3f0d638bd.zip cpython-f1ad207f2ab67d76c062c342b2832ae3f0d638bd.tar.gz cpython-f1ad207f2ab67d76c062c342b2832ae3f0d638bd.tar.bz2 |
Made several grammatical corrections based on comments from Daniel
Barcla <danielb@digitalfocus.com>.
Also added example of what happens when a parameter is set both
positionally and by a keyword (one of Daniels suggestions related to
that paragraph).
Diffstat (limited to 'Doc/tut/tut.tex')
-rw-r--r-- | Doc/tut/tut.tex | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index 9c8d9e8..c373733 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -1266,9 +1266,20 @@ parrot(actor='John Cleese') # unknown keyword In general, an argument list must have any positional arguments followed by any keyword arguments, where the keywords must be chosen from the formal parameter names. It's not important whether a formal -parameter has a default value or not. No argument must receive a +parameter has a default value or not. No argument may receive a value more than once --- formal parameter names corresponding to positional arguments cannot be used as keywords in the same calls. +Here's an example that fails due to this restriction: + +\begin{verbatim} +>>> def function(a): +... pass +... +>>> function(0, a=0) +Traceback (innermost last): + File "<stdin>", line 1, in ? +TypeError: keyword parameter redefined +\end{verbatim} When a final formal parameter of the form \code{**\var{name}} is present, it receives a dictionary containing all keyword arguments @@ -1393,7 +1404,8 @@ the front of the list, and \code{a.insert(len(a), x)} is equivalent to \code{a.append(x)}. \item[\code{append(x)}] -Equivalent to \code{a.insert(len(a), x)}. +Append an item to the list; +equivalent to \code{a.insert(len(a), x)}. \item[\code{index(x)}] Return the index in the list of the first item whose value is \code{x}. @@ -1605,7 +1617,7 @@ is also possible, e.g.: \end{verbatim} This is called, appropriately enough, \emph{tuple unpacking}. Tuple -unpacking requires that the list of variables on the left has the same +unpacking requires that the list of variables on the left have the same number of elements as the length of the tuple. Note that multiple assignment is really just a combination of tuple packing and tuple unpacking! @@ -1629,7 +1641,7 @@ Another useful data type built into Python is the \emph{dictionary}. Dictionaries are sometimes found in other languages as ``associative memories'' or ``associative arrays''. Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by \emph{keys}, -which can be any non-mutable type; strings and numbers can always be +which can be any immutable type; strings and numbers can always be keys. Tuples can be used as keys if they contain only strings, numbers, or tuples. You can't use lists as keys, since lists can be modified in place using their \code{append()} method. @@ -1687,8 +1699,8 @@ only matters for mutable objects like lists. All comparison operators have the same priority, which is lower than that of all numerical operators. -Comparisons can be chained: e.g., \code{a < b == c} tests whether \code{a} -is less than \code{b} and moreover \code{b} equals \code{c}. +Comparisons can be chained: e.g., \code{a < b == c} tests whether +\code{a} is less than \code{b} and moreover \code{b} equals \code{c}. Comparisons may be combined by the Boolean operators \code{and} and \code{or}, and the outcome of a comparison (or of any other Boolean @@ -1806,11 +1818,9 @@ following command: >>> import fibo \end{verbatim} -This does not enter the names of the functions defined in -\code{fibo} +This does not enter the names of the functions defined in \code{fibo} directly in the current symbol table; it only enters the module name -\code{fibo} -there. +\code{fibo} there. Using the module name you can access the functions: \begin{verbatim} |