Classes
Create a class
class Movie:
def __init__(self, title, rating, year):
self.title = title
self.rating = rating
self.year = year
def __repr__(self):
return f"Title: {self.title}\tRating: {self.rating}\tYear: {self.year}"
movie = Movie(title="The Dark Knight", rating=9.0, year=2008)
When you print(movie) the __repr__() function are called, and we got
print(movie)
Title: The Dark Knight Rating: 9.0 Year: 2008
with @dataclass decorator
from dataclasses import dataclass
@dataclass
class Movie:
title: str
rating: float
year: int