Python 构造函数无法获取输入参数
我是Python新手。我一直在关注有关python类的在线教程,但我遇到了一个奇怪的错误 我不知道我到底做了什么 下面是我的代码:Python 构造函数无法获取输入参数,python,linux,class,error-handling,constructor,Python,Linux,Class,Error Handling,Constructor,我是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 = mar
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();
下面是错误:
回溯(最近一次调用last):文件“main.py”,第14行,在
student1=StudentData('Ali',12,90)类型错误:此构造函数采用
没有争论
有人能解释我为什么会犯这个错误吗
很抱歉提出了一个蹩脚的问题:(\uuuu init\uuuu()
应该在两边都有两个下划线,因此python将您的函数视为类中的普通函数
更改:
def _init_(self,name,age,marks):
到
\uuuu init\uuuu()
的两边应该有两个下划线,因此python将您的函数视为类中的普通函数
更改:
def _init_(self,name,age,marks):
到