Python 101 : Data classes - Class decorators -


 


Dataclass is a class decorator that makes it easy for us to create classes that are "data" oriented. for example:


Is equivalent to:


The @dataclass decorator will create both the constructor __init__, the __repr__ , and other functions based on the variables we have provided - brand, color, size -.

Remark:

The size variable was given a default value as follows:

Comments

Leave as a comment:

Archive