What is the difference between an empty default value and default_factory in a dataclass?

Viewed 37

What is the difference between these both dataclass declararions:

@dataclass
class Employee:
    Name: str = ""
    Age:  Int = 25
    Family: dict = field(default_factory=dict)

and

@dataclass
class Employee:
    Name: str = ""
    Age:  Int = 25
    Family: dict = {}

In which cases do you need the first over the second?

0 Answers
Related