# Nested quotes and backslashes now allowed (3.12+)
users =[{"name":"Alice"},{"name":"Bob"}]print(f"First user: {users[0]['name']}")# Multi-line f-string expressions
result = f"Total:{sum(
item['price']for item in[{'price':10},{'price':20}])}"
print(result)
Output
First user: Alice
Total: 30
Note Python 3.12 lifted the restriction on backslashes and same-quote nesting inside f-string expressions. This makes many previously awkward patterns simple.
# New syntax (3.12+) - no more TypeVar boilerplatedef first_element[T](items:list[T])->T:return items[0]print(first_element([10,20,30]))print(first_element(["a","b"]))# Generic classclassPair[A,B]:def__init__(self, left:A, right:B):self.left= left
self.right= right
p =Pair("name",42)print(p.left, p.right)
Output
10
a
name 42
Note The [T] syntax on def/class replaces manual TypeVar declarations. It is scoped to the function or class, unlike module-level TypeVar which could be reused accidentally.
Note TaskGroup replaces asyncio.gather() with structured concurrency. If any task raises, all other tasks are cancelled and errors are collected into an ExceptionGroup.
# Python 3.13 introduced:# 1. Experimental JIT compiler (--enable-experimental-jit)# 2. Free-threaded mode (no GIL) via python3.13t# 3. Improved error messages with colorimport sys
print(f"Python {sys.version}")# Check if GIL is disabled (3.13+)# sys._is_gil_enabled() # returns False in free-threaded build
Note Python 3.13's free-threaded build removes the GIL experimentally. Most C extensions need updating to work without the GIL. The JIT is opt-in and best for CPU-bound loops.
# DeprecationWarning: process_v1: Use process_v2() instead
Note The built-in @deprecated decorator (3.13+, PEP 702) is recognized by type checkers, which will warn callers at analysis time, not just at runtime.