3. Data Classes
These examples show how the dataclasses module simplifies creating and managing data objects while providing flexibility for real-world scenarios. Let me know if you'd like additional examples or furt
from dataclasses import dataclass
@dataclass
class Person:
name: str
age: int
person = Person(name="Alice", age=30)
print(person) # Output: Person(name='Alice', age=30)from dataclasses import dataclass
@dataclass
class Book:
title: str
author: str
price: float = 9.99
book = Book(title="Python 101", author="John Doe")
print(book) # Output: Book(title='Python 101', author='John Doe', price=9.99)Last updated