问答详情
源自:2-4 Python实例属性的初始化

请问这个为什么会运行失败呢

calss Anmial(object):

    def_init_(self,name,age):

       self.name = name

       self.age = age

dog = Person('Tim',4)

cat = Person('Aim',5)

print(dog.name)

print(dog.age)

print(cat.name)

print(cat.age)


提问者:20044031 2021-01-23 21:57

个回答

  • 柳随风
    2021-01-23 22:10:11
    已采纳

    calss Anmial(object):

        def __init__(self,name,age):

           self.name = name

           self.age = age

    dog = Anmial('Tim',4)

    cat = Anmial('Aim',5)

    print(dog.name)

    print(dog.age)

    print(cat.name)

    print(cat.age)



  • weixin_慕斯0352826
    2022-12-13 09:08:24

    定义类上下不一致

  • callie777
    2021-03-30 15:36:33

    class也写错了