Python Evolution from 3.6 to 3.12 | Generated by AI
Question: What are the major changes in Python from version 3.6 to the current version?
Answer:
Python has evolved significantly from version 3.6 (released in December 2016) to the current stable version 3.12 (with maintenance releases up to 3.12.8 as of late 2025). The changes focus on improved syntax, performance, typing support, error handling, and standard library refinements, while removing deprecated features for cleaner code. Below is a summary of the major updates by version, highlighting key language features, library changes, and performance improvements.
Python 3.7 (June 2018)
- Data Class Decorators: Introduced
@dataclassfor concise class definitions with automatic methods like__init__,__repr__, and__eq__(PEP 557). - Type Hints: Added support for typing extensions like
typing.Dict[str, Any]and postponed evaluation of annotations (PEP 563). - Async Improvements:
async/awaitsyntax became standard, withasyncioenhancements for better coroutine handling. - Performance: Faster attribute access and dictionary ordering preservation.
- Library:
contextlib.asynccontextmanagerfor async context managers.
Python 3.8 (October 2019)
- Positional-Only Parameters: Use
/in function signatures to require positional args (PEP 570). - Assignment Expressions: The “walrus operator”
:=for inline assignments (PEP 572), e.g.,if (x := len(s)) > 10:. - f-string Improvements: Allow backslashes and nested quotes in f-strings.
- Performance: Faster startup and memory usage via specialized dictionary types.
- Library:
math.prod()andmath.dist()for product and distance calculations;typing.Literalfor literal types.
Python 3.9 (October 2020)
- Dictionary Union Operators:
|for merging dicts, e.g.,{**a, **b}becomesa | b(PEP 584). - Type Hints:
|for union types (PEP 604), e.g.,str | int; generic aliases likelist[str]. - Pattern Matching Setup: Initial work on structural pattern matching (finalized in 3.10).
- Performance: Faster comprehensions and attribute access.
- Library:
zip()strict mode to prevent early termination; removal of some dead batteries likeasynchat.
Python 3.10 (October 2021)
- Structural Pattern Matching:
match/casestatements for powerful switch-like logic (PEP 634), e.g., matching tuples or objects. - Error Messages: More helpful tracebacks with suggestions, like “Did you mean ‘list’?”.
- Type Hints:
typing.ParamSpecandConcatenatefor better function type tracking. - Performance: ~10-20% faster via adaptive interpreter optimizations.
- Library:
str.removeprefix()andstr.removesuffix(); deprecation ofdistutils(removed in 3.12).
Python 3.11 (October 2022)
- Exception Groups: Handle multiple exceptions at once with
ExceptionGroupandexcept*(PEP 654). - Typing:
Selftype for better method typing;LiteralStringand other refinements. - Performance: Up to 25% faster execution via a new just-in-time (JIT) compiler and frame evaluation optimizations.
- Error Messages: Even better diagnostics, including frame summaries in tracebacks.
- Library:
tomllibfor native TOML parsing;os.walkimprovements for recursive directory traversal.
Python 3.12 (October 2023)
- Type Parameter Syntax: Simplified generics with PEP 695, e.g.,
def func[T](x: T) -> T: ...instead oftyping.TypeVar. - F-string Enhancements: Removed limitations, allowing nested f-strings and expressions like
f"{x=}"for debugging. - Performance: Immortal objects (e.g.,
None) to reduce reference counting overhead; buffer protocol optimizations. - Error Messages: Syntax warnings for invalid escapes; improved
Did you meansuggestions. - Library: Removed deprecated modules like
distutilsandsmtpd; security upgrades tohashlib; Linuxperfprofiler support.
Overall trends include stronger typing support for static analysis, performance gains (Python 3.12 is ~60% faster than 3.6 in benchmarks), and a push toward experimental free-threading (no GIL) in upcoming versions like 3.13. Code from 3.6 remains mostly compatible, but updating for new features and removals is recommended for modern projects.
References:
- What’s New in Python
- Summary of Major Changes Between Python Versions
- The Best New Features in Python 3.12
- Python Changes 2014-2024