Much as Python 2.6 incorporated features from Python 3.0, version 2.7 incorporates some of the new features in Python 3.1. The 2.x series continues to provide tools for migrating to the 3.x series.
A partial list of 3.1 features that were backported to 2.7:
- The syntax for set literals (
{1,2,3}
is a mutable set). - Dictionary and set comprehensions (
{i: i*2 for i in range(3)}
). - Multiple context managers in a single
with
statement. - A new version of the
io
library, rewritten in C for performance. - The ordered-dictionary type described in PEP 372: Adding an Ordered Dictionary to collections.
- The new
","
format specifier described in PEP 378: Format Specifier for Thousands Separator. - The
memoryview
object. - A small subset of the
importlib
module, described below. - The
repr()
of a floatx
is shorter in many cases: it’s now based on the shortest decimal string that’s guaranteed to round back tox
. As in previous versions of Python, it’s guaranteed thatfloat(repr(x))
recoversx
. - Float-to-string and string-to-float conversions are correctly rounded. The
round()
function is also now correctly rounded. - The
PyCapsule
type, used to provide a C API for extension modules. - The
PyLong_AsLongAndOverflow()
C API function.
Other new Python3-mode warnings include:
operator.isCallable()
andoperator.sequenceIncludes()
, which are not supported in 3.x, now trigger warnings.- The
-3
switch now automatically enables the-Qwarn
switch that causes warnings about using classic division with integers and long integers.
No comments:
Post a Comment