From 6885587018e800a2ce3d45eba89d838f83470542 Mon Sep 17 00:00:00 2001 From: Caleb Curry Date: Sat, 15 Mar 2025 09:17:14 -0400 Subject: [PATCH 1/7] fix number --- beginner_python/06-loop-basics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beginner_python/06-loop-basics.py b/beginner_python/06-loop-basics.py index 643d310..b46c060 100644 --- a/beginner_python/06-loop-basics.py +++ b/beginner_python/06-loop-basics.py @@ -5,7 +5,7 @@ for x in languages: print(x) -#The body of this loop (the indented part) will run 4 times +#The body of this loop (the indented part) will run 3 times #Each time is known as an iteration #Each iteration, the variable x will contain one element #iteration 1 will be the first element From 9790956d84b33d6c686ae01bf7db343f90709f69 Mon Sep 17 00:00:00 2001 From: Caleb Curry Date: Fri, 4 Apr 2025 10:26:08 -0400 Subject: [PATCH 2/7] fix True --- python/08-oop-basics.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/08-oop-basics.py b/python/08-oop-basics.py index eb1956d..cf4a8f9 100644 --- a/python/08-oop-basics.py +++ b/python/08-oop-basics.py @@ -87,7 +87,7 @@ def log(self): def is_short(self): if self.pages < 100: - return true + return True book = Book("Are You My Mother?", 72) book.log() #no need to pass anything to self parameter. @@ -110,7 +110,7 @@ def is_short(self): def book_is_short(book): if book.pages < 100: - return true + return True if book_is_short(book): #do something @@ -151,7 +151,7 @@ def log(self): def is_short(self): if self.pages < 100: - return true + return True book = Book("Are You My Mother?", 72) @@ -180,7 +180,7 @@ def __init__(self, title, pages): def is_short(self): if self.pages < 100: - return true + return True #What happens when you pass object to print? def __str__(self): From 566a3f17053d7d5aa9913891e22e4c61ccf3d8a7 Mon Sep 17 00:00:00 2001 From: Caleb Curry Date: Fri, 4 Apr 2025 10:28:32 -0400 Subject: [PATCH 3/7] return true or false now --- python/08-oop-basics.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/08-oop-basics.py b/python/08-oop-basics.py index cf4a8f9..38c4e30 100644 --- a/python/08-oop-basics.py +++ b/python/08-oop-basics.py @@ -188,8 +188,7 @@ def __str__(self): #What happens when you use ==? def __eq__(self, other): - if(self.title == other.title and self.pages == other.pages): - return True + return self.title == other.title and self.pages == other.pages #It's approriate to give something for __hash__ when you override __eq__ # #This is the recommended way if mutable (like it is here): From bfeb5262cf1268189cf3dfeba843c3c829f9dbce Mon Sep 17 00:00:00 2001 From: Caleb Curry Date: Fri, 4 Apr 2025 10:32:29 -0400 Subject: [PATCH 4/7] improve boolean --- python/08-oop-basics.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/python/08-oop-basics.py b/python/08-oop-basics.py index 38c4e30..dba55e1 100644 --- a/python/08-oop-basics.py +++ b/python/08-oop-basics.py @@ -179,8 +179,7 @@ def __init__(self, title, pages): self.pages = pages def is_short(self): - if self.pages < 100: - return True + return self.pages < 100: #What happens when you pass object to print? def __str__(self): @@ -196,20 +195,14 @@ def __eq__(self, other): #If should immutable, you could do something like this. #This replaces __hash__ = None - def __hash__(self): - return hash(self.title) ^ hash(self.pages) #xor with hash of attributes - #from Mastering Object-Oriented Python + # def __hash__(self): + # return hash(self.title) ^ hash(self.pages) #xor with hash of attributes + # #from Mastering Object-Oriented Python book = Book("Are You My Mother", 72) -print(book) equal_book = Book("Are You My Mother", 72) print("Are they considered equal?", book == equal_book) #yep print("Are they the same object?", book is equal_book) #nope book2 = Book("The Digging-est Dog", 72) -print(hash(book), hash(book2)) - -print("old hash", hash(book)) -book.title = "new" -print("new hash", hash(book)) #BAD!!! -#Hashes shouldn't change \ No newline at end of file +print(hash(book), hash(book2)) \ No newline at end of file From a8143f5ec608b2cf05f8bd606404ace536f97c1c Mon Sep 17 00:00:00 2001 From: Caleb Curry Date: Fri, 4 Apr 2025 10:35:19 -0400 Subject: [PATCH 5/7] typo --- python/08-oop-basics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/08-oop-basics.py b/python/08-oop-basics.py index dba55e1..cd7ce31 100644 --- a/python/08-oop-basics.py +++ b/python/08-oop-basics.py @@ -179,7 +179,7 @@ def __init__(self, title, pages): self.pages = pages def is_short(self): - return self.pages < 100: + return self.pages < 100 #What happens when you pass object to print? def __str__(self): From 69a36b9c28bd9db24523c2c65e78c8d56b2c09f5 Mon Sep 17 00:00:00 2001 From: Caleb Curry Date: Fri, 4 Apr 2025 10:38:27 -0400 Subject: [PATCH 6/7] move new book over --- python/09-objects-io.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/python/09-objects-io.py b/python/09-objects-io.py index 029fc80..dbab3b6 100644 --- a/python/09-objects-io.py +++ b/python/09-objects-io.py @@ -6,8 +6,7 @@ def __init__(self, title, pages): self.pages = pages def is_short(self): - if self.pages < 100: - return true + return self.pages < 100 #What happens when you pass object to print? def __str__(self): @@ -15,8 +14,7 @@ def __str__(self): #What happens when you use ==? def __eq__(self, other): - if(self.title == other.title and self.pages == other.pages): - return True + return self.title == other.title and self.pages == other.pages #It's approriate to give something for __hash__ when you override __eq__ # #This is the recommended way if mutable (like it is here): From c34766df18e59b1c48f5fcef0ba75a97c2605fc3 Mon Sep 17 00:00:00 2001 From: Caleb Curry Date: Fri, 4 Apr 2025 12:59:46 -0400 Subject: [PATCH 7/7] book changes --- python/book.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/python/book.py b/python/book.py index 4e01c73..0e89f6e 100644 --- a/python/book.py +++ b/python/book.py @@ -1,25 +1,20 @@ class Book(): - favs = [] #class + favs = [] def __init__(self, title, pages): self.title = title self.pages = pages def is_short(self): - if self.pages < 100: - return True + return self.pages < 100 - #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 + return self.title == other.title and self.pages == other.pages + - #It's appropriate 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