Discuss / Python / 为什么说Student不接收参数呢。。。

为什么说Student不接收参数呢。。。

Topic source

L刘志颖L

#1 Created at ... [Delete] [Delete and Lock User]

class Student(object): count=0 def init(self,name): self.name=name Student.count+=1

测试:

if Student.count != 0: print('测试失败!') else: bart = Student('Bart') if Student.count != 1: print('测试失败!') else: lisa = Student('Bart') if Student.count != 2: print('测试失败!') else: print('Students:', Student.count) print('测试通过!') input()

D:\dist>python 4.py Traceback (most recent call last): File "4.py", line 39, in <module> bart = Student('Bart') TypeError: Student() takes no arguments

叶面之上

#2 Created at ... [Delete] [Delete and Lock User]

Student类中def init(self,name): 写错了,是__init__函数

L刘志颖L

#3 Created at ... [Delete] [Delete and Lock User]

非常感谢


  • 1

Reply