1212\tableofcontents
1313
1414This article explains the new features in Python 2.4. No release date
15- for Python 2.4 has been set; expect that this will happen in 2004.
15+ for Python 2.4 has been set; expect that this will happen mid- 2004.
1616
1717While Python 2.3 was primarily a library development release, Python
18182.4 may extend the core language and interpreter in
@@ -42,6 +42,7 @@ \section{PEP 218: Built-In Set Objects}
4242set(['a', 'r', 'b', 'c', 'd'])
4343>>> ''.join(a) # convert back into a string
4444'arbcd'
45+
4546>>> b = set('alacazam') # form a second set
4647>>> a - b # letters in a but not in b
4748set(['r', 'd', 'b'])
@@ -51,6 +52,7 @@ \section{PEP 218: Built-In Set Objects}
5152set(['a', 'c'])
5253>>> a ^ b # letters in a or b but not both
5354set(['r', 'd', 'b', 'm', 'z', 'l'])
55+
5456>>> a.add('z') # add a new element
5557>>> a.update('wxy') # add multiple new elements
5658>>> a
@@ -115,6 +117,11 @@ \section{Other Language Changes}
115117language.
116118
117119\begin {itemize }
120+
121+ \item The string methods, \method {ljust()}, \method {rjust()}, and
122+ \method {center()} now take a optional argument for specifying a
123+ fill character other than a space.
124+
118125\item The \method {sort()} method of lists gained three keyword
119126arguments, \var {cmp}, \var {key}, and \var {reverse}. These arguments
120127make some common usages of \method {sort()} simpler. All are optional.
@@ -185,10 +192,12 @@ \section{Other Language Changes}
185192[11, 12, 13, 14, 15, 16, 17, 18, 19]
186193>>> L = [9,7,8,3,2,4,1,6,5] # original is left unchanged
187194[9,7,8,3,2,4,1,6,5]
195+
188196>>> list.sorted('Monte Python') # any iterable may be an input
189197[' ', 'M', 'P', 'e', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y']
198+
199+ >>> # List the contents of a dict sorted by key values
190200>>> colormap = dict(red=1, blue=2, green=3, black=4, yellow=5)
191- >>> # Lists the contents of the dict sorted by key values
192201>>> for k, v in list.sorted(colormap.iteritems()):
193202... print k, v
194203...
@@ -202,7 +211,7 @@ \section{Other Language Changes}
202211
203212
204213\item The \function {zip()} built-in function and \function {itertools.izip()}
205- now return an empty list instead of raising a \exception {TypeError}
214+ now returns an empty list instead of raising a \exception {TypeError}
206215 exception if called with no arguments. This makes the functions more
207216 suitable for use with variable length argument lists:
208217
@@ -297,6 +306,12 @@ \section{Build and C API Changes}
297306 objN)}, constructs tuples from a variable length argument list of
298307 Python objects.
299308
309+ \item A new function, \function {PyDict_Contains(d, k)}, implements
310+ fast dictionary lookups without masking exceptions raised during
311+ the loop-up process (compare with \function {PySequence_Contains()}
312+ which is slower or \function {PyMapping_HasKey()} which clears all
313+ exceptions).
314+
300315\end {itemize }
301316
302317
0 commit comments