class VirtualPet:
def __init__(self, color="red"): # 初始化变量,并可以通过参数赋值
self.color = color
def changeColor(self, new_color): # 可以利用函数修改属性的值
self.color = new_color
rocky = VirtualPet("Brown")
benny = VirtualPet("Black")
catty = VirtualPet()
print(rocky.color)
print(benny.color)
print(catty.color)
catty.changeColor("green")
print(catty.color)