class Bank:def __init__(self, name, balance=0):self.name = nameself.balance = balance# def Display_details(self):# print( self.name),# print(self.balance),#### def Withdraw(self, a):# self.balance -= a# print(f"Balance after withdrawn {self.balance}")### def Deposite(self, b):# self.balance += b# print(f"Balance after deposite {self.balance}")class Book:def __init__(self,isbn, title, author, publisher, pages, price, copies):self.isbn = isbnself.title = titleself.author = authorself.publisher = publisherself.pages = pagesself.price = priceself.copies = copiesdef display(self):print(f"isbn = {self.isbn}")print(f"title = {self.title}")print(f"price = {self.price}")print(f"copies = {self.copies}")def in_stock(self):if self.copies > 0:return Trueelse:return Falsedef shell(self):for i in range(self.copies, 0):if self.copies == 0:print('the book is out of stock')else:self.copies -= 1print(self.copies)book1 = Book('957-4-36-547417-1', 'Learn Physics','Stephen', 'CBC', 350, 200,10)
book2 = Book('652-6-86-748413-3', 'Learn Chemistry','Jack', 'CBC', 400, 220,20)
book3 = Book('957-7-39-347216-2', 'Learn Maths','John', 'XYZ', 500, 300,5)
book4 = Book('957-7-39-347216-2', 'Learn Biology','Jack', 'XYZ', 400, 200,6)book_list = [book1, book2, book3, book4]for i in book_list:print(i.display)
# print(book1.display())
How to access instance object in list and display them?
<bound method Book.display of <__main__.Book object at 0x0000000001D88880>>
<bound method Book.display of <__main__.Book object at 0x0000000001D88CD0>>
<bound method Book.display of <__main__.Book object at 0x0000000001D88BB0>>
<bound method Book.display of <__main__.Book object at 0x00000000007A7400>
its display the book from the instance object declaration and why the
main.Book object at 0x00000000007A7400>
is displayis there and use of __str__
and __repr__
in this?
if i remove the comment from the last line and comment the 2nd line
print(book1.display())
(venv) C:\Users\admin\PycharmProjects\ankitt>bank.py
isbn = 957-4-36-547417-1
title = Learn Physics
price = 200
copies = 10
None