1
     ˆÂÅ„q …ŸÁÄÃ ?÷     ****************************
  What's New in Python 2.4
****************************

:Author: A.M. Kuchling

.. |release| replace:: 1.02

.. $Id: whatsnew24.tex 54632 2007-03-31 11:59:54Z georg.brandl $
.. Don't write extensive text for new sections; I'll do that.
.. Feel free to add commented-out reminders of things that need
.. to be covered.  --amk

This article explains the new features in Python 2.4.1, released on March 30,
2005.

Python 2.4 is a medium-sized release.  It doesn't introduce as many changes as
the radical Python 2.2, but introduces more features than the conservative 2.3
release.  The most significant new language features are function decorators and
generator expressions; most other changes are to the standard library.

According to the CVS change logs, there were 481 patches applied and 502 bugs
fixed between Python 2.3 and 2.4.  Both figures are likely to be underestimates.

This article doesn't attempt to provide a complete specification of every single
new feature, but instead provides a brief introduction to each feature.  For
full details, you should refer to the documentation for Python 2.4, such as the
Python Library Reference and the Python Reference Manual.  Often you will be
referred to the PEP for a particular new feature for explanations of the
implementation and design rationale.

.. ======================================================================


PEP 218: Built-In Set Objects
=============================

Python 2.3 introduced the :mod:`sets` module.  C implementations of set data
types have now been added to the Python core as two new built-in types,
:func:`set(iterable)` and :func:`frozenset(iterable)`.  They provide high speed
operations for membership testing, for eliminating duplicates from sequences,
and for mathematical operations like unions, intersections, differences, and
symmetric differences. ::

   >>> a = set('abracadabra')              # form a set from a string
   >>> 'z' in a                            # fast membership testing
   False
   >>> a                                   # unique letters in a
   set(['a', 'r', 'b', 'c', 'd'])
   >>> ''.join(a)                          # convert back into a string
   'arbcd'

   >>> b = set('alacazam')                 # form a second set
   >>> a - b                               # letters in a but not in b
   set(['r', 'd', 'b'])
   >>> a | b                               # letters in either a or b
   set(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'])
   >>> a & b                               # letters in both a and b
   set(['a', 'c'])
   >>> a ^ b                               # letters in a or b but not both
   set(['r', 'd', 'b', 'm', 'z', 'l'])

   >>> a.add('z')                          # add a new element
   >>> a.update('wxy')                     # add multiple new elements
   >>> a
   set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'x', 'z'])
   >>> a.remove('x')                       # take one element out
   >>> a
   set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'z'])

The :func:`frozenset` type is an immutable version of :func:`set`. Since it is
immutable and hashable, it may be used as a dictionary key or as a member of
another set.

The :mod:`sets` module remains in the standard library, and may be useful if you
wish to subclass the :class:`Set` or :class:`ImmutableSet` classes.  There are
currently no plans to deprecate the module.


.. seealso::

   :pep:`218` - Adding a Built-In Set Object Type
      Originally proposed by Greg Wilson and ultimately implemented by Raymond
      Hettinger.

.. ======================================================================


PEP 237: Unifying Long Integers and Integers
============================================

The lengthy transition process for this PEP, begun in Python 2.2, takes another
step forward in Python 2.4.  In 2.3, certain integer operations that would
behave differently after int/long unification triggered :exc:`FutureWarning`
warnings and returned values limited to 32 or 64 bits (depending on your
platform).  In 2.4, these expressi