from abc import ABC, abstractmethod
@abstractmethod
修飾器建立抽象方法from abc import ABC, abstractmethod
class A(ABC):
@abstractmethod
def base(self):
pass
a = A()
# 錯誤
# TypeError: Can't instantiate abstract class A with abstract methods base
class ModeB(A):
# 透過繼承抽象類別 A
def base(self):
print("Mode B")
# 新的內容
b = ModeB()
b.base()
# Mode B
from abc import ABC, abstractmethod
class A(ABC):
@abstractmethod
def base(self):
pass
class ModeB(A):
def base(self):
print("Mode B")
class ModeC(A):
def base(self):
print("Mode C")
b = ModeB()
c = ModeC()
b.base()
# Mode B
c.base()
# Mode C
明天將最近幾天的類別內容做一個彙整