python学习笔记-01
2019-05-08 本文已影响0人
Jane93
运行报错
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__