Discuss / Python / 子类-父类

子类-父类

Topic source

岁益寒

#1 Created at ... [Delete] [Delete and Lock User]

# -*- coding: utf-8 -*-

class Animal(object):

    def run(self):

        print('Animal is running...')

    def run_twice(self):

        self.run()

        self.run()

class Dog(Animal):

    def run(self):

        print('Dog is running...')

class Cat(Animal):

    def run(self):

        print('Cat is running...')

a = Animal()

b = Dog()

c = Cat()

print(isinstance(a, Animal))

print(isinstance(b, Dog))

print(isinstance(c, Cat))

print(isinstance(a, Dog))

a.run_twice()

b.run_twice()

c.run_twice()

岁益寒

#2 Created at ... [Delete] [Delete and Lock User]

之前学过等于再复习,这速度有点慢,到今天已经一周多了


  • 1

Reply