美文网首页python学习
python学习笔记-01

python学习笔记-01

作者: Jane93 | 来源:发表于2019-05-08 08:09 被阅读0次

运行报错

Python出现错误:==TypeError: object() takes no parameters==


错误代码

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))

    def get_grade(self):
        if self.score>=90:
            return 'A'
        elif self.score >=60:
            return 'B'
        else:
            return 'C'
bart=Student('Bart Simpson',59)
lisa=Student('Lisa Simpson',87)

print('bart.name=',bart.name)
print('bart.score=',bart.score)

bart.print_score()

错误原因:

将 __init__  错写成了 __int__

相关文章

网友评论

    本文标题:python学习笔记-01

    本文链接:https://www.haomeiwen.com/subject/cpspoqtx.html