Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Python
Stage 5: Specialization

Part 16 / Topic 6 of 6

What's new in modern Python

Python ships a new minor version every year, roughly every October. "What's new in 3.x" pages exist for every release and are long; the table below only lists changes big enough to matter day to day, each one checked by actually running it on this course's own interpreter (run python --version; this lesson was checked on CPython 3.14.8) before being written down. Full, runnable program: examples/04_version_features_tour.py (the excerpt further down comes straight from a real run of it).

Since Feature What changed, in short
3.10 match/case structural pattern matching: case int():, case [x, y]:, case {"k": v}:, not just a fancy if/elif
3.10 X | Y as a type int | str works directly as a type hint, no typing.Union[int, str] needed
3.11 tomllib reading TOML (like pyproject.toml itself) needs no install any more
3.11 ExceptionGroup / except* one try can report and selectively catch several unrelated exceptions at once
3.11 faster CPython the "Faster CPython" project's first big release; no code changes needed to benefit
3.12 f-strings (PEP 701) reuse the same quote character inside { }, and span multiple lines, inside an f-string
3.12 generic syntax def first[T](items: list[T]) -> T: and class Box[T]:, no typing.TypeVar needed
3.12 type statement type RupeeAmount = int | float makes a named, reusable type alias
3.13 free-threaded build (PEP 703) an optional build of CPython without the GIL, for true multi-core threads (Part 13); check with sys._is_gil_enabled() if the attribute exists
3.13 REPL improvements colours, multi-line editing and better history at the interactive python prompt — open a plain python prompt to see it, a script cannot show this
3.13 copy.replace() one function to make a changed copy of any supporting object (not just a dataclasses.replace()-style dataclass)
3.14 deferred annotations (PEP 649) a function can be defined with an annotation that refers to a not-yet-existing name; it only matters if something actually reads __annotations__
3.14 template strings, t"..." (PEP 750) like an f-string, but gives you the pieces (.strings, .interpolations) unformatted, for safe building of SQL/HTML/shell text
3.14 compression.zstd the fast Zstandard compression format joins gzip/bz2/lzma in the standard library

Verified, real output (excerpt, from examples/04_version_features_tour.py, run on CPython 3.14.8 — the full run also covers 3.11 and 3.13):

== 3.10: match/case, and X | Y as a union type ==
  classify(5): int
  classify('a'): str
  int | str annotation works without typing.Union: int | str

== 3.12: f-string improvements (PEP 701), generic syntax, `type` statement ==
  same-quote nesting: Pune
  generic function first([10, 20, 30]): 10
  type alias name: RupeeAmount

== 3.14: deferred annotations, t-strings, compression.zstd ==
  defined a function annotated with an undefined name: no NameError
  its annotation, read back as text (no evaluation): {'x': 'NotYetDefined', 'return': 'None'}
  t-string .strings / .interpolations: (('Hello, ', '!'), ['name'])
  compression.zstd round-trip ok: True

3.15 and anything newer: not covered here — this lesson's interpreter is 3.14.8, and claiming details of a release this course has not actually run would be a guess, not a fact. Check python --version, then read the official What's New page for exactly that version: https://docs.python.org/3/whatsnew/.

Exercise 6: A feature-availability report

Scenario: A platform team runs the same tool on servers with different Python versions, and wants it to say exactly which modern features it can rely on, instead of crashing with a confusing error. What to do: Write one small function per feature, then a feature_report() that returns a dict[str, bool]:

  1. has_tomllib(): try import tomllib inside the function; return whether it worked.
  2. has_exception_groups(): ExceptionGroup/except* need Python 3.11+; check sys.version_info.
  3. has_generic_syntax(): def f[T](): needs 3.12+.
  4. has_free_threading_flag(): the sys._is_gil_enabled attribute itself only exists from 3.13 on; check with hasattr.
  5. has_t_strings(): t"..." template strings need 3.14+.

In main(), print the interpreter's major.minor version, then every feature from feature_report() as <feature>: yes/no. Finally print whether all of them are available (all(report.values())).

Sample output (on CPython 3.14):

Interpreter: CPython 3.14
  tomllib: yes
  ExceptionGroup/except*: yes
  generic syntax def f[T](): yes
  free-threading flag (sys._is_gil_enabled): yes
  t-strings: yes
Ready for every demo in this part: True

💡 Hint: On an older interpreter every line still prints; only the yes/no values and the final line change, because each check is a version number or hasattr comparison, never code that could raise SyntaxError just by being parsed.

Show the solution to Exercise 6
"""Exercise 6: A feature-availability report for the running interpreter.

Run:   python ex06.py   (macOS/Linux: python3 ex06.py)
"""

import sys


def has_tomllib() -> bool:
    try:
        import tomllib  # noqa: F401
        return True
    except ImportError:
        return False


def has_exception_groups() -> bool:
    return sys.version_info >= (3, 11)          # ExceptionGroup/except* need 3.11+


def has_generic_syntax() -> bool:
    return sys.version_info >= (3, 12)           # def f[T](): ... needs 3.12+


def has_free_threading_flag() -> bool:
    return hasattr(sys, "_is_gil_enabled")        # the flag itself appeared in 3.13


def has_t_strings() -> bool:
    return sys.version_info >= (3, 14)            # PEP 750, needs 3.14+


def feature_report() -> dict[str, bool]:
    return {
        "tomllib": has_tomllib(),
        "ExceptionGroup/except*": has_exception_groups(),
        "generic syntax def f[T]()": has_generic_syntax(),
        "free-threading flag (sys._is_gil_enabled)": has_free_threading_flag(),
        "t-strings": has_t_strings(),
    }


def main() -> None:
    print(f"Interpreter: CPython {sys.version_info.major}.{sys.version_info.minor}")
    for feature, available in feature_report().items():
        mark = "yes" if available else "no"
        print(f"  {feature}: {mark}")

    report = feature_report()
    ready_for_3_14_demo = all(report.values())
    print("Ready for every demo in this part:", ready_for_3_14_demo)


if __name__ == "__main__":
    main()

Search the guide