I. Overview of Python Version Evolution
Python did not have today's syntax and ecosystem from the beginning. It underwent a long evolution from an early interpreted scripting language to a modern general-purpose programming language.
Version upgrades not only added syntax features but also continuously improved interpreter performance, the standard library, the type system, concurrency capabilities, and the developer experience.
1. The Birth of Python
Python was designed by Guido van Rossum starting in the late 1980s and was first publicly released in 1991.
One of the original goals in designing Python was to create a programming language with clear syntax that was easy to read and easy to extend.
Python's design was influenced by projects such as the ABC language and also absorbed excellent features from other languages. It did not pursue syntactic complexity but emphasized code readability and development efficiency.
Early Python already had several important characteristics:
- Uses indentation to organize code blocks.
- Supports dynamic typing.
- Provides built-in data structures such as lists and dictionaries.
- Supports functions, modules, and exception handling.
- Has cross-platform operating capability.
- Provides an extensible interpreter implementation.
These designs laid the foundation for the development of later versions.
2. Timeline of Major Python Versions
Python version numbers usually use:
major version.minor version.maintenance version
For example:
3.15.2
│ │ │
│ │ └── Maintenance release: bug and security fixes
│ └───── Minor release: adds language and standard library features
└──────── Major release: represents significant compatibility evolution
Major version upgrades of Python are not frequent. Python 2 to Python 3 was a highly impactful incompatible upgrade.
| Version | Release Date | Main Significance |
|---|---|---|
| Python 0.9 | 1991 | The earliest public version, with basic capabilities such as classes, exceptions, and functions |
| Python 1.0 | 1994 | An early official version; language capabilities gradually improved |
| Python 2.0 | 2000 | Introduced list comprehensions, garbage collection, and other important improvements |
| Python 2.7 | 2010 | The final major minor release in the Python 2 series |
| Python 3.0 | 2008 | Carried out language cleanup and incompatible adjustments |
| Python 3.5 | 2015 | Introduced async and await syntax |
| Python 3.6 | 2016 | Introduced f-strings |
| Python 3.7 | 2018 | Introduced data classes; dictionary insertion order became guaranteed by the language specification |
| Python 3.8 | 2019 | Introduced the walrus operator |
| Python 3.9 | 2020 | Introduced dictionary merge operators |
| Python 3.10 | 2021 | Introduced structural pattern matching |
| Python 3.11 | 2022 | Interpreter performance and exception handling capabilities improved |
| Python 3.12 | 2023 | Improved type parameter syntax and interpreter internals |
| Python 3.13 | 2024 | Introduced capabilities such as an experimental free-threaded build |
| Python 3.14 | 2025 | Introduced template strings, deferred evaluation of annotations, and other features |
| Python 3.15 | 2026 | Introduced explicit lazy imports, frozendict, and other new capabilities |
Note that the release dates and features in the table are only evolutionary milestones and do not represent all changes in each version.
3. The Development of Python 2
Python 2.0 was released in 2000 and was a very important version in Python's development.
It brought several improvements to the language and runtime mechanisms, such as:
- List comprehensions.
- Garbage collection mechanisms.
- Enhanced Unicode support.
- A more complete standard library.
- Richer language expressiveness.
Afterward, the Python 2 series continued to develop, forming a large number of mature third-party libraries, development frameworks, and enterprise projects.
Python 2.7 was released in 2010 and became the final major minor release in the Python 2 series.
With the introduction of Python 3, the Python community gradually shifted development focus to the new version. To give legacy projects time to migrate, the maintenance period for Python 2.7 was extended multiple times.
Ultimately, Python 2 officially ended support on January 1, 2020.
This means Python 2 no longer receives official regular maintenance and security updates. Historical projects may still run Python 2, but new projects should no longer choose it.
4. The Birth of Python 3
Python 3.0 was released in 2008.
It did not simply add features on top of Python 2; rather, it carried out a systematic cleanup of the language design.
During Python 2's long development process, some historical design issues had accumulated, such as:
- The boundary between strings and byte data was not clear enough.
- Some syntax was inconsistent.
- The behavior of built-in functions was not uniform enough.
- Some historical interfaces were redundant.
- Some designs were difficult to continue evolving.
Python 3 reworked these designs through a series of incompatible changes.
One of the most important changes was a clear distinction between text and binary data:
# Python 3
text = "你好"
data = b"你好"
print(type(text)) # <class 'str'>
print(type(data)) # <class 'bytes'>
This design makes string processing, file I/O, and network communication more explicit.
However, because Python 3 introduced incompatible changes relative to Python 2, many early Python 2 projects could not run directly on Python 3.
As a result, the adoption of Python 3 went through a long migration phase.
5. The Continued Evolution of Python 3
Python 3 is not a version with a fixed feature set; it is a continuously evolving language series.
Its main directions of evolution include:
- Enhanced syntactic expressiveness.
- Gradual refinement of the type system.
- Improved interpreter execution efficiency.
- Enhanced concurrency and asynchronous programming capabilities.
- Continued expansion of the standard library.
- Continuous improvement of development tools and the ecosystem.
- Continuous improvement in support for modern hardware and runtime environments.
For example:
Python 3.5 introduced async and await, giving asynchronous programming more intuitive syntax.
Python 3.6 introduced f-strings, simplifying string formatting.
Python 3.10 introduced match and case, providing structured pattern matching.
Python 3.11 significantly optimized interpreter execution efficiency and enhanced exception handling capabilities.
Python 3.12 improved how generics and type parameters are expressed.
Python 3.13 introduced an experimental free-threaded build, allowing developers to explore execution models that do not rely on the traditional GIL.
Python 3.14 introduced template strings, deferred evaluation of annotations, and standard library support for subinterpreters.
Python 3.15 continues to advance capabilities such as lazy imports, immutable dictionary types, and UTF-8 as the default encoding.
It can be seen that the evolution of Python 3 not only focuses on syntax but also places increasing emphasis on runtime performance, concurrency models, and engineering capabilities.
II. Core Differences Between Python 2 and Python 3
Python 2 and Python 3 are highly similar in syntax, but they are not two fully compatible versions.
To understand the differences between the two, particular attention should be paid to strings, numeric operations, iterators, input/output, and exception handling.
1. Changes to print
In Python 2, print is a statement.
# Python 2
print "Hello Python"
print "Hello", "World"
In Python 3, print is a built-in function.
# Python 3
print("Hello Python")
print("Hello", "World")
The function form in Python 3 supports keyword arguments:
print("Hello", "World", sep="-")
print("Hello", end="!")
Output:
Hello-World
Hello!
This change makes output behavior more consistent and also makes it easier to pass the print function as an object.
2. Changes to Strings and Unicode
This is one of the most important differences between Python 2 and Python 3.
In Python 2:
strusually represents a byte sequence.unicoderepresents Unicode text.
# Python 2
text = u"你好"
data = "hello"
print(type(text)) # unicode
print(type(data)) # str
In Python 3:
strrepresents Unicode text.bytesrepresents a byte sequence.
# Python 3
text = "你好"
data = b"hello"
print(type(text)) # <class 'str'>
print(type(data)) # <class 'bytes'>
Python 3 clearly separates text and binary data.
This is very important for file operations, network communication, database interaction, and character encoding handling.
For example:
text = "你好"
# Encode text to bytes
data = text.encode("utf-8")
# Decode bytes to text
result = data.decode("utf-8")
print(data)
print(result)
Conversion relationship:
Unicode text
|
| encode("utf-8")
v
UTF-8 byte sequence
|
| decode("utf-8")
v
Unicode text
Some things to note:
- Encoding is converting text into bytes.
- Decoding is restoring bytes back into text.
- Calling
decode()on text that is alreadystris usually incorrect. - Calling
encode()on data that is alreadybytesis usually incorrect as well.
3. Changes to division
Python 2 and Python 3 differ in how they handle integer division by default.
In Python 2, if both operands are integers, / usually performs integer division.
# Python 2
print(5 / 2) # 2
In Python 3, / always performs true division.
# Python 3
print(5 / 2) # 2.5
If you need division that rounds down, use //:
print(5 // 2) # 2
print(-5 // 2) # -3
There is a detail here that is easy to overlook:
// does not simply drop the fractional part; it rounds toward negative infinity.
Therefore:
int(-5 / 2) # -2
-5 // 2 # -3
The two results are not the same.
4. Changes to the integer type
Python 2 divides integers into two main types:
int: ordinary integers.long: integers that can represent a larger range.
When an integer exceeds the range representable by int, Python 2 can use long.
Python 3 unifies the two into int.
# Python 3
number = 123456789012345678901234567890
print(type(number))
# <class 'int'>
Python 3 integers support arbitrary precision; the size of an integer is limited mainly by available memory.
This reduces the burden on developers of dealing with integer type conversions.
5. Changes to range and xrange
Python 2 has two commonly used functions:
range(): returns a list.xrange(): returns a lazy iterable object.
# Python 2
numbers = range(5)
lazy_numbers = xrange(5)
Python 3 removed xrange() and made range() behave in a similar lazy-iteration way.
# Python 3
numbers = range(5)
print(numbers)
# range(0, 5)
print(list(numbers))
# [0, 1, 2, 3, 4]
Python 3's range does not create a list containing all the elements in advance; instead, it produces integers on demand as you iterate.
It is therefore well suited to representing large integer ranges.
6. Changes to map, filter and zip
In Python 2, map(), filter() and zip() usually return lists.
In Python 3, they return iterators.
# Python 3
numbers = [1, 2, 3, 4]
result = map(lambda x: x * 2, numbers)
print(result)
# <map object ...>
print(list(result))
# [2, 4, 6, 8]
If you need a list result, you have to convert it explicitly:
result = list(map(lambda x: x * 2, numbers))
This design can reduce unnecessary memory allocation, and is especially well suited to handling large amounts of data.
But note that an iterator can usually be consumed only once, from start to finish:
result = map(lambda x: x * 2, [1, 2, 3])
print(list(result))
print(list(result))
The second conversion yields an empty list, because the iterator has already been exhausted.
7. Dictionary iteration and order guarantees
Ordinary dictionaries in Python 2 do not guarantee iteration in insertion order.
The CPython implementation in Python 3.6 began preserving dictionary insertion order, but at the time this was still an implementation detail.
Starting with Python 3.7, dictionary insertion order became a guarantee of the language specification.
# Python 3.7+
user = {
"name": "Alice",
"age": 20,
"city": "Beijing"
}
for key, value in user.items():
print(key, value)
The output order matches the insertion order.
In addition, Python 3.9 introduced the dictionary merge operator:
user = {"name": "Alice"}
profile = {"age": 20}
result = user | profile
print(result)
# {'name': 'Alice', 'age': 20}
This makes dictionary merging more concise.
8. Changes to input
Python 2 has two common input functions:
raw_input(): reads user input and returns a string.input(): reads input and attempts to evaluate it as a Python expression.
In Python 3, input() uniformly adopts the string-reading behavior.
# Python 3
name = input("请输入姓名:")
print(name)
If a numeric value is needed, it must be converted explicitly:
age = int(input("请输入年龄:"))
This design reduces the security risks of executing user input directly as code.
9. Changes to exception handling syntax
The exception handling syntax differs between Python 2 and Python 3.
Python 2 allows:
# Python 2
try:
result = 10 / 0
except ZeroDivisionError, error:
print(error)
Python 3 uses as to bind the exception object:
# Python 3
try:
result = 10 / 0
except ZeroDivisionError as error:
print(error)
The Python 3 form is more consistent and easier to align with other syntax rules.
10. Changes to the class and object model
Python 2 has both old-style classes and new-style classes.
Old-style class:
# Python 2
class User:
pass
New-style class:
# Python 2
class User(object):
pass
Python 3 uniformly adopts the new-style class model.
# Python 3
class User:
pass
In Python 3, all classes are based on the unified new-style class mechanism, so behaviors such as method resolution order, descriptors, and attribute access are more consistent.
11. Changes to iterators and generators
Both Python 2 and Python 3 support iterators and generators, but Python 3 unified the related interfaces.
For example, the dictionary methods commonly seen in Python 2:
# Python 2
user = {"name": "Alice", "age": 20}
keys = user.keys()
values = user.values()
items = user.items()
In Python 3, these methods return dynamic view objects:
# Python 3
user = {"name": "Alice", "age": 20}
keys = user.keys()
values = user.values()
items = user.items()
print(list(keys))
print(list(values))
print(list(items))
Dictionary views reflect subsequent changes to the dictionary, rather than holding an independent result as an ordinary list does.
If you need a fixed snapshot of the data, you can explicitly convert it to a list.
12. Changes to the standard library and module structure
Python 3 reorganized the standard library, and some modules were renamed, merged, or removed.
For example:
| Python 2 | Python 3 |
|---|---|
urllib2 |
urllib.request, urllib.error, etc. |
ConfigParser |
configparser |
Queue |
queue |
StringIO |
io.StringIO |
cPickle |
pickle |
Python 3 also changed the behavior of some standard library APIs.
Therefore, when migrating old projects, you cannot only modify the syntax; you also need to check dependencies, module imports, and interface changes.
III. Comparison Summary of Python 2 and Python 3
The following is a consolidated comparison of the two based on common development scenarios.
| Comparison Aspect | Python 2 | Python 3 |
|---|---|---|
| print statement | print function | |
| Text type | unicode |
str |
| Byte type | str |
bytes |
| Integer type | int, long |
Unified as int |
| Integer division | / usually performs integer division |
/ performs true division |
| Floor division | // |
// |
| Range function | range, xrange |
range |
| map | Usually returns a list | Returns an iterator |
| filter | Usually returns a list | Returns an iterator |
| zip | Usually returns a list | Returns an iterator |
| Dictionary order | Insertion order not guaranteed | Guaranteed as of Python 3.7 |
| Input function | raw_input, input |
input |
| Exception binding | Supports old-style comma syntax | Uses as |
| Class model | Old-style and new-style classes coexist | Unified as new-style classes |
| Unicode | The boundary between text and bytes is more complex | str and bytes are clearly distinguished |
| Official support | Ended in 2020 | Continuously maintained and evolving |
It should be emphasized that the differences between Python 2 and Python 3 go beyond what is shown in the table. In particular, third-party libraries, C extensions, file encodings, and runtime environments are often the most complicated parts of migrating large projects.
IV. Important Features in Various Stages of Python 3
The development of Python 3 can be understood along several directions: language expressiveness, type system, execution performance, and concurrency capabilities.
1. Python 3.0: Reorganization of the Language Specification
Python 3.0 was a major language upgrade.
Main changes include:
printbecame a function.strrepresents Unicode text by default.bytesis used to represent binary data./performs true division by default.- Removed some historical syntax and interfaces.
- Unified the class model.
- Adjusted the standard library structure.
The goal of Python 3.0 was not to let old code run without modification, but to establish a more consistent foundation for the language's future development.
2. Python 3.5: Enhanced Asynchronous Programming Capabilities
Python 3.5 introduced the async and await syntax.
import asyncio
async def fetch_data():
await asyncio.sleep(1)
return "data"
async def main():
result = await fetch_data()
print(result)
asyncio.run(main())
This allows Python to write asynchronous programs using more intuitive syntax.
It is especially suitable for:
- High-concurrency network requests.
- Asynchronous web services.
- Asynchronous database access.
- A large number of I/O-intensive tasks.
Note that async and await do not mean the code runs in parallel automatically. They are mainly for cooperative concurrency and rely on the event loop to schedule coroutines.
3. Python 3.6: f-strings and Developer Experience Improvements
Python 3.6 introduced f-strings.
name = "Alice"
age = 20
message = f"{name} is {age} years old"
print(message)
Compared with traditional string formatting, f-strings can embed expressions directly in the string.
price = 19.99
count = 3
print(f"Total: {price * count:.2f}")
f-strings make string formatting more concise and intuitive.
4. Python 3.7: Data Classes and Guaranteed Dict Ordering
Python 3.7 introduced the dataclasses standard library.
from dataclasses import dataclass
@dataclass
class User:
name: str
age: int
user = User("Alice", 20)
print(user)
Data classes can automatically generate common methods such as initializers and string representations based on field declarations.
At the same time, dictionary insertion order became a guarantee of the language specification.
These changes reduce repetitive code and improve consistency in how data structures are used.
5. Python 3.8: The Walrus Operator
Python 3.8 introduced the assignment expression operator :=, also known as the walrus operator.
if (length := len("Python")) > 5:
print(length)
It allows assignment to be performed within an expression.
Another common scenario is reading data in a loop:
while (line := input("Enter content: ")) != "quit":
print(line)
The walrus operator can reduce repeated computation, but it should not be overused just to shorten code.
6. Python 3.9: Dict Merging and Type Annotation Improvements
Python 3.9 introduced the dictionary merge operator:
user = {"name": "Alice"}
extra = {"age": 20}
result = user | extra
At the same time, built-in containers can be used directly in type annotations:
names: list[str] = ["Alice", "Bob"]
scores: dict[str, int] = {
"Alice": 90,
"Bob": 85
}
It is no longer necessary to import legacy generic aliases such as List and Dict from typing for these simple type annotations.
7. Python 3.10: Structural Pattern Matching
Python 3.10 introduced match and case.
def handle_status(status):
match status:
case 200:
return "Success"
case 404:
return "Not found"
case 500:
return "Server error"
case _:
return "Unknown status"
Structural pattern matching can match not only constants but also sequences, mappings, class instances, and complex data structures.
It is well suited to handling data with multiple structural branches.
8. Python 3.11: Interpreter Performance and Exception Handling Improvements
Python 3.11 applied a number of optimizations to the interpreter.
Main changes include:
- Significantly faster interpreter execution.
- More precise error messages.
- Introduction of
ExceptionGroup. - Introduction of the
except*syntax. - Improved asynchronous tasks and debugging experience.
For example, an exception group can represent multiple exceptions raised in a single operation:
errors = ExceptionGroup(
"Multiple tasks failed",
[
ValueError("Invalid argument"),
TypeError("Type mismatch")
]
)
try:
raise errors
except* ValueError as group:
print("Handling ValueError")
except* TypeError as group:
print("Handling TypeError")
This is especially useful in scenarios where several exceptions occur at the same time in concurrent tasks.
9. Python 3.12: Type System and Interpreter Improvements
Python 3.12 improved the type parameter syntax.
def first[T](items: list[T]) -> T:
return items[0]
This syntax can directly declare generic type parameters, reducing reliance on the traditional TypeVar in some scenarios.
Python 3.12 also introduced more flexible f-string parsing capabilities and continued to improve the interpreter's internal structure.
10. Python 3.13: Free-Threading Exploration and Runtime Evolution
Python 3.13 introduced an experimental free-threaded build.
Traditional CPython has the GIL, or global interpreter lock. It limits the ability of multiple threads to execute Python bytecode at the same time.
The free-threaded build attempts to provide an execution mode that does not rely on the traditional GIL, giving multithreaded computations a chance to make fuller use of multicore processors.
However, note the following:
- The free-threaded build is not exactly the same runtime environment as the regular build.
- Third-party C extensions need to adapt to thread-safety requirements.
- Not all programs will automatically gain performance improvements.
- Developers still need to handle thread-safety issues.
Therefore, free-threading capabilities should be evaluated in light of actual dependencies and workloads.
11. Python 3.14: Template Strings and Deferred Evaluation of Annotations
Python 3.14 was released in 2025 and brought several language and standard library changes.
The more important changes include:
Template Strings
Introduced t-prefixed strings, which can create template string objects and enable subsequent processing and customized transformations.
name = "Alice"
template = t"Hello, {name}"
Template strings differ from traditional f-strings. Rather than simply generating the final text immediately, they preserve the interpolation structure for later processing.
Deferred Evaluation of Annotations
Python 3.14 improved how annotations are evaluated, reducing the problems caused in some scenarios by type annotations being evaluated immediately at definition time.
Standard Library Support for Subinterpreters
The standard library has added support for subinterpreter-related capabilities, providing more infrastructure for isolated execution environments and concurrent execution.