2

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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
JFerro
  • 3,203
  • 7
  • 35
  • 88
  • It should be a duplicate of this instead: https://stackoverflow.com/questions/53632152/why-cant-dataclasses-have-mutable-defaults-in-their-class-attributes-declaratio – mkrieger1 Feb 06 '22 at 18:53

0 Answers0