def get_grade(self):
if self.__score>=90:
return 'A-优秀'
elif self.__score>=60 :
return 'B-及格'
elif self.__score>=0:
return 'C-不及格'
else:
return '成绩有误'
if self.__score>=90:
return 'A-优秀'
elif self.__score>=60 :
return 'B-及格'
elif self.__score>=0:
return 'C-不及格'
else:
return '成绩有误'
2017-08-09
def cmp_ignore_case(s1, s2):
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-08-09
def count_1():
fs = []
for i in range(1,4):
def g():
return i*i
fs.append(g())
return fs
g1,g2,g3 = count_1()
print g1
print g2
print g3
fs = []
for i in range(1,4):
def g():
return i*i
fs.append(g())
return fs
g1,g2,g3 = count_1()
print g1
print g2
print g3
2017-08-08
ipython 下:
sorted?
Docstring: sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list
Type: builtin_function_or_method
可以查看sorted函数的具体参数
sorted?
Docstring: sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list
Type: builtin_function_or_method
可以查看sorted函数的具体参数
2017-08-08
def fn(x,y):
return x*y
def calc_prod(lst):
def re_prod():
return reduce(fn,lst)
return re_prod
f = calc_prod([1, 2, 3, 4])
print f()
return x*y
def calc_prod(lst):
def re_prod():
return reduce(fn,lst)
return re_prod
f = calc_prod([1, 2, 3, 4])
print f()
2017-08-08
import math
def is_sqr(x):
return (float)(math.sqrt(x))-(int)(math.sqrt(x)) == 0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return (float)(math.sqrt(x))-(int)(math.sqrt(x)) == 0
print filter(is_sqr, range(1, 101))
2017-08-08