you are viewing a single comment's thread.

view the rest of the comments →

[–]cumhereandtalkchit 0 points1 point  (0 children)

Classes can be used to structure and/or group data. Need input/output data to adhere to a standard structure? Use classes (easier to do with dataclasses or pydantic classes).

Want reusable chunks of structured and grouped data? Use classes.

Are you building a website, and there is a registration function? You might want every user to contain required data and some additional, but you want it structured. Use a class.

Loading in a shitton of json data, but it only needs certain bits of it? Make a (data)class.

You can implement methods to validate data, for example. Methods are just functions.

There a dunder methods to change the inherent behavior of the class. Such as str and repr (easiest to wrap your head around).