class Book():
def __init__(self, title, author, pages):
self.title = title
self.author = author
self.pages = pages
def __str__(self):
return f"Title: {self.title}, Author: {self.author}, Pages: {self.pages}"
def __len__(self):
return self.pages
def __del__(self):
print("a book is destroyed!")
myBook = Book("The Fourth Industrial Revolution", "Klaus Schwab", 287)
print(str(myBook))
=> Title: The Fourth Industrial Revolution, Author: Klaus Schwab, Pages: 287
print(len(myBook))
=> 287
del myBook
=> a book is destroyed!