定义函数时候传入(self, score) 和(self)有什么区别
class Student(object):
def __init__(self, name, score):
self.name = name
self.__score = score
@property
def score(self):
return self.__score
@score.setter
def score(self, score):
if score < 0 or score > 100:
raise ValueError('invalid score')
self.__score = score
#注释内容是我的代码
''' @grade.setter
def grade(self, score):
if score > = 80:
self.__grade ='A'
elif score < 60:
self.__grade = 'C'
else self.__grade = 'B''''
#下面是老师答案
@property
def grade(self):
if self.score < 60:
return 'C'
if self.score < 80:
return 'B'
return 'A'
s = Student('Bob', 59)
print s.grade
s.score = 60
print s.grade
s.score = 99
print s.grade
问一下,定义函数时候传入(self, score) 和(self)有什么区别?以及后面使用 self.__grade ='A'和直接return会有什么不一样?