def calc_prod(lst):
def calc_delay():
s=1
for x in lst:
s=s*x
return s
return calc_delay
f = calc_prod([1, 2, 3, 4])
print f()
def calc_delay():
s=1
for x in lst:
s=s*x
return s
return calc_delay
f = calc_prod([1, 2, 3, 4])
print f()
2016-05-04
def cmp_ignore_case(s1, s2):
if s1.upper()>s2.upper():
return 1
elif s1.upper()<s2.upper():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.upper()>s2.upper():
return 1
elif s1.upper()<s2.upper():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-05-04
self.p * r.q + self.q * r.p, self.q * r.q
就是p/q + r.p/r.q = ( p * r.q + q * r.p ) /q * r.q
self省略看得清爽些
就是p/q + r.p/r.q = ( p * r.q + q * r.p ) /q * r.q
self省略看得清爽些
2016-05-04
def calc_prod(lst):
def test():
mul=1;
for i in lst:
mul*=i
return mul
return test
f = calc_prod([1, 2, 3, 4])
print f()
def test():
mul=1;
for i in lst:
mul*=i
return mul
return test
f = calc_prod([1, 2, 3, 4])
print f()
2016-05-04
def cmp_ignore_case(s1, s2):
temp1=s1.lower();
temp2=s2.lower();
if temp1<temp2:
return -1;
if temp1>temp2:
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'],cmp_ignore_case)
temp1=s1.lower();
temp2=s2.lower();
if temp1<temp2:
return -1;
if temp1>temp2:
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'],cmp_ignore_case)
2016-05-04
python3,p1.get_grade = types.MethodType(fn_get_grade, p1, Person)改为p1.get_grade = types.MethodType(fn_get_grade, p1)
2016-05-04
已采纳回答 / 慕粉1462109115
问题:IndentationError: expected an indented block:原因:因为你的return语句没有缩进。解决:在return语句前加两个(自定义)空格
2016-05-04
def count():
fs = []
for i in range(1, 4):
def return_data(j):
def f():
return j*j
return f
fs.append(return_data(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def return_data(j):
def f():
return j*j
return f
fs.append(return_data(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2016-05-04
def calc_prod(lst):
def return_prod():
def lazy_calc_prod(x,y):
return x*y
return reduce(lazy_calc_prod,lst)
return return_prod
f = calc_prod([1, 2, 3, 4])
print f()
def return_prod():
def lazy_calc_prod(x,y):
return x*y
return reduce(lazy_calc_prod,lst)
return return_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-05-04
def cmp_ignore_case(s1, s2):
return cmp(s1.lower(),s2.lower())
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
return cmp(s1.lower(),s2.lower())
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-05-04
def calc_prod(lst):
def prod():
x = 1
for y in lst:
x = x * y
return x
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def prod():
x = 1
for y in lst:
x = x * y
return x
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-05-04