import math
def is_sqr(x):
return x and x%math.sqrt(x)==0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return x and x%math.sqrt(x)==0
print filter(is_sqr, range(1, 101))
2019-09-17
def calc_prod(lst):
def cal():
return reduce(lambda x,y: x*y,lst)
return cal
f = calc_prod([1, 2, 3, 4])
print f()
def cal():
return reduce(lambda x,y: x*y,lst)
return cal
f = calc_prod([1, 2, 3, 4])
print f()
2019-09-13
def calc_prod(lst):
return reduce(lambda x,y: x*y,lst)
f = calc_prod([1, 2, 3, 4])
print f
return reduce(lambda x,y: x*y,lst)
f = calc_prod([1, 2, 3, 4])
print f
2019-09-11
已采纳回答 / Tennis荔枝
lower后面少了括号哦~def format_name(s): return s[0].upper()+s[1:].lower()print map(format_name, ['adam', 'LISA', 'barT'])
2019-09-10
import types
def fn_get_grade(self):
if self.score >=80:
return 'A'
class Person(object):
def __init__(self, name, score):
self.name = name
self.score = score
p1 = Person('Bob', 90)
p1.get_grade = types.MethodType(fn_get_grade, p1, Person)
print p1.get_grade()
def fn_get_grade(self):
if self.score >=80:
return 'A'
class Person(object):
def __init__(self, name, score):
self.name = name
self.score = score
p1 = Person('Bob', 90)
p1.get_grade = types.MethodType(fn_get_grade, p1, Person)
print p1.get_grade()
2019-09-10
最赞回答 / CrMelo7
@performancedef factorial(n): return reduce(lambda x,y: x*y, range(1, n+1))这三句执行之后factorial = performance(factional),factorial(10)实际上是fn(10),这是performance中return fn的效果,fn(10)中return f(10),这里执行的f(10)是factorial = performance(factional)中作为参数传入的factional,返...
2019-09-09
def format_name(s):
return s[0].upper()+s[1:].lower()
print(list(map(format_name, ['adam', 'LISA', 'barT'])))
return s[0].upper()+s[1:].lower()
print(list(map(format_name, ['adam', 'LISA', 'barT'])))
2019-09-09
最赞回答 / 五岁麻瓜少年
<...code...>首先,代码先执行f1,f2,f3=count(),调用count()函数,然后经历循环,i=1, 然后执行r=t(1),fs.append(t(1)),然后返回fs,然后继续循环 i=2, r=t(2),fs.append((t2)),i=3,r=t(3),fs.append((t3)),结束循环,此时fs中[t(1),t(2),t(3)]也就是[g1,g2,g3),最后print f1(),f2(),f3()调用def g()函数分别在i=1,2,3的情况下的数值
2019-09-08
最赞回答 / 小黑鼠
def log(prefix): #222222创建log函数 传入装饰器参数 log('DEBUG') def log_decorator(f): #44444创建log_decorator函数传入被装饰函数,f=test()为参数 def wrapper(*args, **kw): #66666...
2019-09-05