我是 Python 新手。我一直在关注有关 python 类的在线教程,但出现了一个奇怪的错误。
我不知道我做了什么。
下面是我的代码:
class StudentData:
"Contains information of all students"
studentNumber = 0;
def _init_(self,name,age,marks):
self.name = name;
self.age = age;
self.marsk = marks;
def displayStudentNUmber(self):
print 'Total Number of students = ',studentNumber;
def displayinfo(self):
print 'Name of the Student: ',name;
print 'Age of the Student: '.age;
print 'Marks of the Student: '.marks;
student1 = StudentData('Ayesha',12,90)
student2 = StudentData('Sarah',13,89)
print "Student number in case of student 1",student1.displayStudentNumber();
print "Information of the Student",student1.dispalyinfo();
print "Student number in case of student 1",student2.displayStudentNumber();
print "Information of the Student",student2.dispalyinfo();
以下是错误:
Traceback(最近一次调用最后一次):文件“main.py”,第 14 行,在 student1 = StudentData('Ali',12,90) 类型错误:此构造函数不接受任何参数
任何人都可以解释为什么我会收到此错误。
对不起一个蹩脚的问题:(