class Animal(object): def run(self): print('Animal is running...') class Dog(Animal): def run(self):# 继承的好处:多态 print('Dog is running...') def eat(self): print('Eating meat...') class Cat(Animal): def run(self): print('Cat is running...') # 实例化dog dog= Dog() dog.run() # 实例化cat cat= Cat() cat.run() # 判断类型 a=list() # a是list类型 b=Animal()# b是Animal类型 c=Dog()# c是Dog类型 result1=isinstance(c,Dog) print(result1) result2=isinstance(c,Animal)# c属于dog,也属于父类 print(result2)
标签:...,run,继承,self,多态,Dog,面向对象,Animal,print From: https://www.cnblogs.com/haha1988/p/17554438.html