Sobes.tech
Middle

What new features were introduced in Python from version 3.7?

sobes.tech AI

Answer from AI

PEP 563 - Deferred evaluation of type annotations.

PEP 538 - Enforcing the use of UTF-8 locale.

PEP 38 - The dataclasses module.

PEP 564 - New high-resolution time functions.

PEP 567 - Context variable change.

PEP 553 - The breakpoint() function.

PEP 572 - The assignment operator := (Walrus operator).

Dictionary improvements: insertion order is now guaranteed by the language specification.

Improvements in the asyncio module: new APIs and performance enhancements.

Improvements in the typing module.

Changes in the C API.

# Example of using dataclasses
from dataclasses import dataclass

@dataclass
class Person:
    name: str
    age: int

p = Person("Alice", 30)
print(p) # Output: Person(name='Alice', age=30)
# Example of using the Walrus operator (Python 3.8+)
if (n := len([1, 2, 3])) > 2:
    print(f"The list contains more than 2 elements: {n}")