使用 ABC 实现正式接口
在本练习中,您将练习实现一个使用 ABC 类和 @abstractmethod 装饰器创建的正式接口。Business 接口已经为您创建,如下所示。祝您顺利!
class Business(ABC):
@abstractmethod
def sell_product(self, product_name, price, quantity):
pass
本练习是课程的一部分
Python 面向对象编程进阶
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a class that inherits the Business interface
class ____(____):
def __init__(self, business_name):
self.business_name = business_name
# Attempt to create a Bakery object, observe the exception
____:
blue_eyed_baker = ____("Blue Eyed Baker")
____ Exception ____ e:
print(____)