# code:utf-8 #导入 ABCMeta abstractmethodd from abc import ABCMeta, abstractmethod, abstractproperty class Parent(metaclass=ABCMeta): #2.+ 中以次此种方法 #Python 中没有接口的概念 __metaclass__ = ABCMeta def __init__(self): print("parent init ...") #抽象属性 @abstractproperty def name(self): pass @abstractmethod def test(self): pass class Son(Parent): def __init__(self): print("son init ...") def test(self): print("i`m son") __name = "testName" def name(self): return self.__name #3.0 + # class(metaclass=ABCMeta) 以此种方式,否则实例时不会报错 s = Son() print(s.name())