请让我知道为什么会出现AttributeError:'Students'对象没有属性'displayStudent'
班级学生: def init(个人,姓名,年龄): self.name =名字 self.age =年龄 班级学生: def init(个人,姓名,年龄): self.name =名字 self.age =年龄
def displayStudent(self):
return("Student name is" + self.name + "and age is" + str(self.age))
stu =学生(“乍得”,15) stu.displayStudent()
When I ran your code I got an error in the class definition because
def displayStudent
was at a different indentation level from thedef __init__
. Fixed it up and it works fine:也许有一些缩进错误。这是正确的代码。