问答详情
源自:2-3 Python实例属性的定义

还是显示运行失败

calss Animal(object):

    def_init_(self,name,age) 

    self.name = name

    self.age = age

dog = Animal() 

cat = Animal()

dog.name = 'Tim'

dog.age = 4

cat.name = 'Aim'

cat.age = 5

print(dog.name)

print(dog.age)

print(cat.name)

print(cat.age)


提问者:20044031 2021-01-22 18:49

个回答

  • 柳随风
    2021-01-23 19:44:25
    已采纳

    calss 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)


  • yolongs
    2021-02-28 16:16:06

    class Animal(object):#class 拼写错误
        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)