# Product.py # Chapter 5 # static methods page 57 # we use static methods when we want to add functionality to the class, but the return does NOT need to DIRECTLY be in the instance of the class # utility function OOP # static it can not modify anything about a class aka read only class Product: # base class 'super class' def __init__(self, name, price): self.name = name self.price = price # pass the price, apply the discount percent, return new price @staticmethod def apply_discount(price, discount): return price - discount # coupon for $25 off 100-25 return 75 # instance method to apply the disount and give an updated price def update_price(self, discount): self.price = self.apply_discount(self.price, discount) # Inheritance page 60 class ProductDetails(Product): # inheritance / sub / child class def __init__(self, name, price, description): super().__init__(name, price) self.description = description # Program class product_price = 100 product = Product("Widget 1", product_price) print(f"{product.name}'s original price: ${product.price:.2f}") # $100.00 discount_price = Product.apply_discount(product_price, 25) print(f"Discounted Price: ${discount_price:.2f}") # $75.00 product2 = ProductDetails("Widget 1", product_price, "Whats a widget")