class Animal: # 父类 可以把多个类共通的方法和属性提取出来
a = "dd"
def eat(self):
print("吃东西")
def drink(self):
print("水")
def sleep(self):
print("闭眼睡觉")
class NewZebra(Animal): # 子类 继承父类的时候,必须把父类作为形参
count= 1 # 类变量
def __init__(self, name):
self.name = name
def eat(self): # 重写父类方法
animal = super() # super 实例化自己的父类
animal.eat() # 父类的实例对象调用的是父类的方法
print("吃稻草")
global count # 如果想用类变量要加上global
print(count)
count +=1
def colour(self):
print("身上有条纹")
nz = NewZebra("斑马") #
nz.eat()
print("=====")
nz.drink()
nz.sleep()
nz.colour()