【Python爬虫類】Pythonオブジェクトとクラス
817 ワード
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')