简单面向对象编程
class Persons:
def __init__(self,name,age):
self.name = name,
self.age = age
def details(self):
print(self.name)
print(self.age)
zs = Persons('zs',23)
print(zs.name,zs.age)
zs.details()
def sample(class_name):
obj = class_name()
details = obj.details()
return details
if __name__ =='__mian__':
sample(Persons)
继承父类
class Animal:
def eat(self):
print("%s吃饭" %self.name)
def drink(self):
print("%s喝水" %self.name)
def run(self):
print("%s跑" %self.name)
class Cat(Animal):
def __init__(self,name):
self.name = name
def Cry(self):
print("喵喵")
class Dog(Animal):
def __init__(self,name):
self.name = name
def Cry(self):
print("汪汪")
cat = Cat('黑猫')
cat.eat()
cat.Cry()