Sobes.tech
Junior — Middle

Have you used dataclass for defining data structures in Python?

sobes.tech AI

Answer from AI

In Python, dataclass is used for convenient definition of classes that mainly serve to store data. It automatically generates methods like __init__, __repr__, __eq__, and others, reducing boilerplate code.

Example:

from dataclasses import dataclass

@dataclass
class User:
    id: int
    name: str
    active: bool = True

user = User(1, "Ivan")
print(user)

This approach is useful for structuring data, for example, when working with configurations, query results, or passing parameters between functions.