python TypeError: takes no arguments

今天在继续学习python的过程遇到了如标题的这个这个问题,反复查看代码总感觉没啥问题啊写的,原始代码如下

class Student(object):

    def __int__(self, name, score):
        self.name = name
        self.score = score

    def print_score(self):
        print('%s %s' % (self.name, self.score))


上面的代码明面写的看起来是没什么问题,后来经过一番搜索发现是初始化单词写错了,不是

__int__

而应该是

__init__

这个问题完全是因为大意把单词写错了,纠正过的代码如下

class Student(object):

    def __init__(self, name, score):
        self.name = name
        self.score = score

    def print_score(self):
        print('%s %s' % (self.name, self.score))

整体来说这个问题就是粗心马虎造成的,以后不管是学习还是工作的过程中一定要细心。

0 0 投票数
文章评分
订阅评论
提醒
guest
0 评论
内联反馈
查看所有评论
京ICP备17066706号-1
0
希望看到您的想法,请您发表评论x