class Animal(object):
def_init_(self,name,age):
self.name = name
self.age = age
dog = Animal('Tim',4)
cat = Animal('Aim',5)
print(dog.name)
print(dog.age)
print(cat.name)
print(cat.age)
class Animal(): def __init__(self,name,age): self.name = name self.age = age print('{}今年{}岁'.format(name,age)) dog = Animal('汪汪',18) cat = Animal('喵喵',30)
class Animal(object): def __init__(self, name, age): self.name = name self.age = age dog = Animal('Tim', 4) cat = Animal('Aim', 5) print(dog.name) print(dog.age) print(cat.name) print(cat.age)
def后有个空格,init前后是两个下划线