def get_grade(self):
self.res = ''
if self.__score > 80 and self.__score < 100:
self.res = u"A-优秀"
elif self.__score > 60 and self.__score < 80:
self.res = u"B-及格"
else:
self.res = u"C-不及格"
return self.res
self.res = ''
if self.__score > 80 and self.__score < 100:
self.res = u"A-优秀"
elif self.__score > 60 and self.__score < 80:
self.res = u"B-及格"
else:
self.res = u"C-不及格"
return self.res
2016-07-15
用了
print (type(p1.get_grade))
print (type(p1.get_grade()))
结果
<class 'function'>
<class 'str'>
[Finished in 0.2s]
上面是function,说明lambda:'A'这个东西是函数,而下面的东西是字符串,说明p1.get_grade()返回了一个字符串
print (type(p1.get_grade))
print (type(p1.get_grade()))
结果
<class 'function'>
<class 'str'>
[Finished in 0.2s]
上面是function,说明lambda:'A'这个东西是函数,而下面的东西是字符串,说明p1.get_grade()返回了一个字符串
2016-07-14
这题难就难在运用 __cmp__ 方法时对于返回的值是 1 还是 -1 的理解,还有同时运用 __cmp__ 方法比较name和score的
2016-07-14
def calc_prod(lst):
def prod():
s = 1
for x in lst:
s = s*x
return s
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def prod():
s = 1
for x in lst:
s = s*x
return s
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-07-13