python中硬要写抽象类和抽象方法
由于python没有抽象类、接口的概念,所以要实现这种功能得abc.py这个类库,具体方式如下:
# coding: utf-8
import abc
#抽象类
class StudentBase(object):
      __metaclass__ = abc.ABCMeta
      @abc.abstractmethod
      def study(self):
            pass
      def play(self):
            print("play")
# 实现类
class GoodStudent(StudentBase):
      def study(self):
            print("study hard!")
if __name__ == '__main__':
      student = GoodStudent()
      student.study()
      student.play()
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号