标签:tin 强制 def metaclass 子类 eth imp sel pre
#抽象类
import abc
class Animal(metaclass=abc.ABCMeta):
@abc.abstractmethod #强制子类
def eat(self):
pass
@abc.abstractmethod
def run(self):
pass
class Peeple(Animal):
def eat(self):
print(‘peeple is eating‘)
def run(self):
print(‘peeple is runing‘)
class Dag(Animal):
def eat(self):
print(‘dag is eating‘)
def run(self):
print(‘dag is runing‘)
peo1=Peeple()
dag1=Dag()
peo1.eat()
dag1.eat()
标签:tin 强制 def metaclass 子类 eth imp sel pre
原文地址:http://blog.51cto.com/13399294/2285576