美文网首页Python四期爬虫作业
【Python爬虫】Python对象和类

【Python爬虫】Python对象和类

作者: d1b0f55d8efb | 来源:发表于2017-08-27 15:59 被阅读9次
class Animal(object):
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def walk(self,w_step):
        print('{} walk step -> {}'.format(self.name,w_step))

    def say(self,say_str):
        print('{} say : {}'.format(self.name,say_str))

class Dog(Animal):
    def say(self,say_str):
        print('Dog {} say : {}'.format(self.name,say_str))

class Cat(Animal):
    def say(self,say_str):
        print('Cat {} say : {}'.format(self.name,say_str))

def test_say(animal,say_str):
    animal.say(say_str)

if __name__=="__main__":
    d = Dog("Dg", 3)
    c = Cat("Ct", 3)

    d.say("hello")
    c.say("hello")

    # test_say(d,'hello')
    # test_say(c,'hello')

相关文章

网友评论

    本文标题:【Python爬虫】Python对象和类

    本文链接:https://www.haomeiwen.com/subject/guzbdxtx.html