Python Basic Object-Oriented Python Emulating Built-ins Emulating Built-ins

Create a __str__ method for this book class. Return a string with the author and title of the book. Ex: John Green, Pape

Can somebody please be so kind and post the complete code for this tasks 1,2,3 i want to compare it with my mess that i did. I have been trying to resolve this for to long now. Please post the code so i can compare it.

1 Answer

Jassim Al-Hatem
Jassim Al-Hatem
16,940 Points

Task 1 and 2

class Book:
    def __init__(self, author, title): = author
        self.title = title

    def __str__(self):
        return "{}, {}".format(, self.title)

    def __eq__(self, other):
        return + self.title == other

Task 3

from book import Book

class BookCase:
    def __init__(self):
       self.books = []

    def add_books(self, book):

    def __iter__(self):
        yield from self.books

Thank you so much, this was the real deal answer. I made so many mistakes in my code with this one that i completely erased it at the end, now i understand better this whole task.

Kind Regards