Post-init: Add Init Method to a Data Class

With a data class, you don’t need an init method to assign values to its attributes. However, sometimes you might want to use an init method to initialize certain attributes.

That is when dataclass’s __post_init__ comes in handy.  

In the code above, I use __post_init__ to initialize the attribute info using the attributes names and ages.

My previous tips on dataclass.

Related Posts

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran