The fourth edition was updated to cover Python 3.0 and 2.6, and incorporated a small number of major changes made in 3.1. Its 3.0 and 3.1 changes apply to all future releases in the 3.X line including this fifth edition’s Python 3.3, and its 2.6 changes are also part of this edition’s 2.7. As noted earlier, some of the changes described here as 3.X changes also later found their way into Python 2.7 as back-ports (e.g., set literals, and set and dictionary comprehensions).
In addition to the 3.0 and 2.6 changes listed in upcoming sections, shortly before going to press the fourth edition was also augmented with notes about prominent extensions in the then upcoming Python 3.1 release, including:
Comma separators and automatic field numbering in string format method calls (Chapter 7)
Multiple context manager syntax in with statements (Chapter 34)
New methods for number objects (Chapter 5)
(Not added until this fifth edition) Floating-point display changes (Chapter 4 and Chapter 5)
This fifth edition covers these topics in the chapters just noted. Because Python 3.1 was targeted primarily at optimization and was released relatively soon after 3.0, the fourth edition also applied directly to 3.1. In fact, because Python 3.1 superseded 3.0 entirely, and because the latest Python is usually the best Python to fetch and use anyhow, whenever that edition used the term “Python 3.0” it generally referred to the language variations introduced by Python 3.0 but that are present in the entire 3.X line, including this edition’s Python 3.3.
One notable exception: the fourth edition did not incorporate 3.1’s new repr display scheme for floating-point numbers. The new display algorithm attempts to display floating-point numbers more intelligently when possible, usually with fewer (but occasionally with more) decimal digits—a change that is reflected in this fifth edition.
The fourth edition’s language changes stem from Python 3.0 and 2.6. All of its 2.6 and many of its 3.0 changes are shared by Python 2.7 and 3.3 today. Python 2.7 was extended with some 3.0 features not present in 2.6 (see earlier in this appendix), and Python 3.3 inherits all the features introduced by 3.0.
Because there were so many changes in the initial 3.X release, they are noted only briefly in tables here, with links to more details in this book. Table C-1 provides the first set of 3.X changes, listing the most prominent new language features covered in the fourth edition, along with the primary chapters in the current fifth edition in which they appear.
Table C-1. Extensions in Python 2.6 and 3.0
|
Extension |
Covered in chapter(s) |
|---|---|
|
The |
|
|
The |
|
|
The |
|
|
String types in 3.0: |
|
|
Text and binary file distinctions in 3.0 |
|
|
Class decorators in 2.6 and 3.0: |
|
|
New iterators in 3.0: |
|
|
Dictionary views in 3.0: |
|
|
Division operators in 3.0: remainders, |
|
|
Set literals in 3.0: |
|
|
Set comprehensions in 3.0: |
|
|
Dictionary comprehensions in 3.0: |
|
|
Binary digit-string support in 2.6 and 3.0: |
|
|
The fraction number type in 2.6 and 3.0: |
|
|
Function annotations in 3.0: |
|
|
Keyword-only arguments in 3.0: |
|
|
Extended sequence unpacking in 3.0: |
|
|
Relative import syntax for packages enabled in 3.0: |
|
|
Context managers enabled in 2.6 and 3.0: |
|
|
Exception syntax changes in 3.0: |
|
|
Exception chaining in 3.0: |
|
|
Reserved word changes in 2.6 and 3.0 |
|
|
New-style class cutover in 3.0 |
|
|
Property decorators in 2.6 and 3.0: |
|
|
Descriptor use in 2.6 and 3.0 |
|
|
Metaclass use in 2.6 and 3.0 |
|
|
Abstract base classes support in 2.6 and 3.0 |
In addition to extensions, a number of 2.X language tools have been removed in 3.X in an effort to clean up its design. Table C-2 summarizes the 3.X removals that impact this book, covered in various chapters of this edition as noted. As also shown in this table, many of the 3.X removals have direct replacements, some of which are also available in 2.6 and 2.7 to support future migration to 3.X.
Table C-2. Removals in Python 3.0 that impact this book
|
Removed |
Replacement |
Covered in chapter(s) |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
old |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sort comparison functions |
Use |
|
|
Dictionary |
Compare |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Redefine |
|
|
|
Inconsistent tabs/spaces use is always an error |
|
|
|
May only appear at the top level of a file |
|
|
|
|
|
|
|
|
|
|
|
Built-in scope, library manual |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String-based exceptions |
Class-based exceptions (also required in 2.6) |
|
|
String module functions |
String object methods |
|
|
Unbound methods |
Functions ( |
|
|
Mixed type comparisons, sorts |
Nonnumeric mixed type magnitude comparisons (and sorts) are errors |