summaryrefslogtreecommitdiffstats
path: root/Doc/tut
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-06-27 23:36:47 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-06-27 23:36:47 (GMT)
commit5a34afb745f9279191d3220833193354fda18852 (patch)
treed855052fd1a66701548884c60ea94207b967cdf0 /Doc/tut
parent3e3b699adf8100347f87af5cf65e1345f49595ad (diff)
downloadcpython-5a34afb745f9279191d3220833193354fda18852.zip
cpython-5a34afb745f9279191d3220833193354fda18852.tar.gz
cpython-5a34afb745f9279191d3220833193354fda18852.tar.bz2
* Show the keyword argument form of dict().
* Note that dict works with the "in" keyword.
Diffstat (limited to 'Doc/tut')
-rw-r--r--Doc/tut/tut.tex14
1 files changed, 12 insertions, 2 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex
index 48db9f9..40ced7c 100644
--- a/Doc/tut/tut.tex
+++ b/Doc/tut/tut.tex
@@ -2146,8 +2146,8 @@ value using a non-existent key.
The \method{keys()} method of a dictionary object returns a list of all
the keys used in the dictionary, in arbitrary order (if you want it
sorted, just apply the \method{sort()} method to the list of keys). To
-check whether a single key is in the dictionary, use the
-\method{has_key()} method of the dictionary.
+check whether a single key is in the dictionary, either use the dictionary's
+\method{has_key()} method or the \keyword{in} keyword.
Here is a small example using a dictionary:
@@ -2166,6 +2166,8 @@ Here is a small example using a dictionary:
['guido', 'irv', 'jack']
>>> tel.has_key('guido')
True
+>>> 'guido' in tel
+True
\end{verbatim}
The \function{dict()} constructor builds dictionaries directly from
@@ -2183,6 +2185,14 @@ Later in the tutorial, we will learn about Generator Expressions
which are even better suited for the task of supplying key-values pairs to
the \function{dict()} constructor.
+When the keys are simple strings, it is sometimes easier to specify
+pairs using keyword arguments:
+
+\begin{verbatim}
+>>> dict(sape=4139, guido=4127, jack=4098)
+{'sape': 4139, 'jack': 4098, 'guido': 4127}
+\end{verbatim}
+
\section{Looping Techniques \label{loopidioms}}