forked from CalebCurry/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.py
More file actions
26 lines (20 loc) · 755 Bytes
/
book.py
File metadata and controls
26 lines (20 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Book():
favs = [] #class
def __init__(self, title, pages):
self.title = title
self.pages = pages
def is_short(self):
if self.pages < 100:
return true
#What happens when you pass object to print?
def __str__(self):
return f"{self.title}, {self.pages} pages long"
#What happens when you use ==?
def __eq__(self, other):
if(self.title == other.title and self.pages == other.pages):
return True
#It's approriate to give something for __hash__ when you override __eq__
# #This is the recommended way if mutable (like it is here):
__hash__ = None
def __repr__(self): #added to make list of items invoke str
return self.__str__()