Suppose I had a piece of code like that.
import collections
User = collections.namedtuple("User", ("id", "name", "email"))A new feature required the possibility of changing the value. As you probably now, the namedtuple is immutable, we can’t change any value.
Traceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: can't set attributeFortunately, Python 3.7 came to the rescue!
Python 3.7 has a new feature, dataclasses. Using @dataclass decorator, I was able to remove namedtuple and modify my data without any issues.
from dataclasses import dataclass
@dataclassclass User: id: int name: str email: str
Now, it’s possible to change the value.
>>> user1.emailOf course, that’s not all that data classes offer!