A .py file has no version marker: the same file can be valid in one
release and not in another. Python 3.0 was a deliberate break with Python 2. Since then
a change that breaks old code has usually come after a deprecation period. New feature
releases have come every October since Python 3.9 (PEP 602). Each is supported for about
five years. Dates in the tables come from the Python developer's guide and the What's New
documents.
Every release
Python 3
| Version | Released | End of life | Added | Removed or changed |
|---|---|---|---|---|
| 3.15 | 9 Oct 2026 | Oct 2031 (planned) | lazy imports (PEP 810). frozendict (PEP 814). sentinel (PEP 661). Unpacking in comprehensions (PEP 798). UTF-8 as the default encoding for open() (PEP 686). math.integer, profiling | __cached__ is no longer set. The import system stops using load_module(). sre_compile, sre_constants and sre_parse removed |
| 3.14 | 7 Oct 2025 | Oct 2030 (planned) | Deferred annotations (PEP 649, PEP 749). Template strings (PEP 750). except without brackets (PEP 758). Free-threaded build officially supported (PEP 779). concurrent.interpreters (PEP 734). compression.zstd (PEP 784). annotationlib | SyntaxWarning for leaving a finally with return, break or continue (PEP 765). NotImplemented as a truth value raises TypeError. int() no longer delegates to __trunc__ |
| 3.13 | 7 Oct 2024 | Oct 2029 (planned) | New interactive prompt. Defined locals() semantics (PEP 667). Experimental free-threaded build (PEP 703) and JIT compiler (PEP 744). Type parameter defaults (PEP 696). TypeIs (PEP 742). ReadOnly (PEP 705). dbm.sqlite3 | 19 modules removed (PEP 594). 2to3, lib2to3 and tkinter.tix removed. Docstrings have common indentation stripped |
| 3.12 | 2 Oct 2023 | Oct 2028 (planned) | Type parameter syntax and type statement (PEP 695). f-strings in the grammar (PEP 701). Per-interpreter GIL (PEP 684). Comprehension inlining (PEP 709). __buffer__ (PEP 688). @override (PEP 698). sys.monitoring (PEP 669) | distutils, asynchat, asyncore, smtpd and imp removed. Invalid escapes now give SyntaxWarning |
| 3.11 | 24 Oct 2022 | Oct 2027 (planned) | Exception groups and except* (PEP 654). Exception notes (PEP 678). Precise error locations (PEP 657). Variadic generics (PEP 646). Self (PEP 673). tomllib. TaskGroup. Starred items in for | @asyncio.coroutine and binhex removed. int and str conversion limited to 4300 digits by default |
| 3.10 | 4 Oct 2021 | 1 Oct 2026 | match statement (PEP 634). X | Y unions (PEP 604). Parenthesised context managers. ParamSpec (PEP 612). TypeAlias (PEP 613). TypeGuard (PEP 647). zip(strict=) (PEP 618). EncodingWarning (PEP 597). Precise line numbers (PEP 626) | Aliases to abstract base classes in collections removed. parser and formatter modules removed |
| 3.9 | 5 Oct 2020 | 31 Oct 2025 | dict merge operators (PEP 584). Generics on built-in types (PEP 585). Relaxed decorators (PEP 614). str.removeprefix (PEP 616). PEG parser (PEP 617). Annotated (PEP 593). zoneinfo (PEP 615) | Last release with the Python 2 compatibility layers. with (await lock): no longer valid |
| 3.8 | 14 Oct 2019 | 7 Oct 2024 | Assignment expressions (PEP 572). Positional-only parameters (PEP 570). f-string =. Audit hooks (PEP 578). Literal, TypedDict, Final, Protocol | continue allowed in finally |
| 3.7 | 27 Jun 2018 | 27 Jun 2023 | dataclasses (PEP 557). breakpoint() (PEP 553). Module __getattr__ (PEP 562). Postponed annotations (PEP 563). UTF-8 mode (PEP 540). Hash-based .pyc files (PEP 552) | async and await become keywords. dict order guaranteed. StopIteration in generators becomes RuntimeError (PEP 479) |
| 3.6 | 23 Dec 2016 | 23 Dec 2021 | f-strings (PEP 498). Variable annotations (PEP 526). Underscores in numbers (PEP 515). Asynchronous generators (PEP 525). Asynchronous comprehensions (PEP 530). __init_subclass__ and __set_name__ (PEP 487). __fspath__ (PEP 519). secrets | Unrecognised escapes deprecated |
| 3.5 | 13 Sep 2015 | 30 Sep 2020 | async and await (PEP 492). @ operator (PEP 465). More unpacking (PEP 448). bytes formatting (PEP 461). Type hints and typing (PEP 484). os.scandir (PEP 471). zipapp | .pyo files replaced by .opt-N.pyc (PEP 488) |
| 3.4 | 16 Mar 2014 | 18 Mar 2019 | asyncio (PEP 3156). enum (PEP 435). pathlib (PEP 428). statistics (PEP 450). tracemalloc (PEP 454). ensurepip (PEP 453). Module specs (PEP 451) | Safer object finalisation (PEP 442) |
| 3.3 | 29 Sep 2012 | 29 Sep 2017 | yield from (PEP 380). raise ... from None (PEP 409). u"" accepted again (PEP 414). Namespace packages (PEP 420). __qualname__ (PEP 3155). venv (PEP 405). py launcher (PEP 397) | Flexible string storage (PEP 393). OSError hierarchy reworked (PEP 3151). Imports built on importlib |
| 3.2 | 20 Feb 2011 | 20 Feb 2016 | __pycache__ (PEP 3147). argparse (PEP 389). concurrent.futures (PEP 3148) | hasattr catches only AttributeError. callable() restored |
| 3.1 | 27 Jun 2009 | 9 Apr 2012 | OrderedDict (PEP 372). Thousands separator (PEP 378). Several managers in one with. Directories and zip files with __main__.py can be run | Shortest round-trip repr for floats |
| 3.0 | 3 Dec 2008 | 27 Jun 2009 | The new language | See the table below |
Python 2
| Version | Released | Added |
|---|---|---|
| 2.7 | 3 Jul 2010 | Set literals. Dictionary and set comprehensions. Several managers in one with. OrderedDict (PEP 372). argparse (PEP 389). Dictionary views as viewkeys() and others (PEP 3106). The last 2.x release, whose support ended on 1 January 2020 (PEP 373) |
| 2.6 | 1 Oct 2008 | with without a future import. str.format (PEP 3101). except E as e (PEP 3110). b'' literals (PEP 3112). 0o and 0b (PEP 3127). Class decorators (PEP 3129). abc (PEP 3119). multiprocessing (PEP 371). print_function (PEP 3105) |
| 2.5 | 19 Sep 2006 | Conditional expressions (PEP 308). Absolute and relative imports (PEP 328). Unified try statement (PEP 341). send and throw on generators (PEP 342). with (PEP 343). BaseException (PEP 352). __index__ (PEP 357) |
| 2.4 | 30 Nov 2004 | Generator expressions (PEP 289). Decorators (PEP 318). Built-in set (PEP 218). reversed (PEP 322). decimal (PEP 327). subprocess (PEP 324) |
| 2.3 | 29 Jul 2003 | Generators without a future import (PEP 255). Source encodings (PEP 263). bool (PEP 285). Import from zip (PEP 273). Import hooks (PEP 302) |
| 2.2 | 21 Dec 2001 | New-style classes, descriptors and super (PEP 252, PEP 253). Iterators (PEP 234). Generators with a future import (PEP 255). // (PEP 238). Unification of int and long (PEP 237) |
| 2.1 | 17 Apr 2001 | Nested scopes with a future import (PEP 227). __future__ (PEP 236). Rich comparisons (PEP 207). Weak references (PEP 205). Function attributes (PEP 232) |
| 2.0 | 16 Oct 2000 | List comprehensions. Augmented assignment. Unicode strings (PEP 100). Cycle-detecting garbage collection. String methods |
From Python 2 to Python 3
Python 3.0 changed these parts of the language. The source of a Python 2 program usually needs editing to run on Python 3.
| Python 2 | Python 3 | PEP |
|---|---|---|
print "x" | print("x") | 3105 |
exec code | exec(code) | |
str is bytes, unicode is text | str is text and bytes is binary. Mixing them is a TypeError | |
| Source defaults to ASCII | Source defaults to UTF-8 | 3120 |
| ASCII identifiers | Non-ASCII identifiers allowed | 3131 |
1 / 2 is 0 | 1 / 2 is 0.5, and 1 // 2 is 0 | 238 |
int and long | One int. No L suffix | 237 |
0777 | 0o777 | 3127 |
except E, e: | except E as e: | 3110 |
raise E, args | raise E(args) | 3109 |
| No chaining | raise E from cause | 3134 |
__metaclass__ = M | class C(metaclass=M): | 3115 |
| Classic classes | All classes are new-style | |
range makes a list; xrange is lazy | range is lazy | |
d.keys() makes a list | A view; iterkeys and others removed | 3106 |
map, filter, zip make lists | They return iterators | |
raw_input() | input() | 3111 |
<> and backquotes | != and repr() | |
cmp() and __cmp__ | Rich comparisons and key= | |
Tuple parameters, def f((a, b)): | Removed | 3113 |
| Mixed types can be ordered | Unrelated types raise TypeError | |
Names such as ConfigParser, Queue | configparser, queue | 3108 |
Python 3.0 also added function annotations (PEP 3107), keyword-only arguments
(PEP 3102), nonlocal (PEP 3104), extended unpacking (PEP 3132), set
displays, and dictionary and set comprehensions.
Later changes that broke source
| Version | Change |
|---|---|
| 3.7 | async and await can no longer be names |
| 3.7 | A StopIteration inside a generator becomes RuntimeError |
| 3.8 | f((keyword)=arg) is no longer allowed |
| 3.9 | with (await lock): is no longer valid |
| 3.10 | collections.Mapping and the other aliases are gone; use collections.abc |
| 3.11 | The 'U' mode of open() is gone |
| 3.12 | distutils and imp are gone |
| 3.13 | 19 standard modules and 2to3 are gone |
| 3.14 | NotImplemented in a Boolean context raises TypeError |
Announced for future versions: ~True and ~False are due to
be removed in 3.16; unrecognised escape sequences will become
SyntaxError; and a number directly followed by a keyword, such as
0in x, will become a SyntaxError.