class Cat:
"""小猫爱吃鱼,小猫爱喝水"""
#传参数
def __init__(self,newname):
#初始化参数,赋值
self.name = newname
def eat(self):
#哪个对象调用这个类,那self就是他本身
#调用属性
print("%s爱吃鱼"%self.name)
def drink(self):
print("%s爱喝水"%self.name)
#创建猫对象
tom =Cat("tom")
tom.eat()
tom.drink()
lazy_cat =Cat("大懒猫")
lazy_cat.eat()
lazy_cat.drink()
class Cat:
def __init__(self,newname):
self.name =newname
print("%s 来了"%self.name)
tom =Cat("tom")
print(tom.name)