def count():
fs = []
for i in range(1, 4):
def f(i):
return lambda:i*i
fs.append(f(i))
return fs
fs = []
for i in range(1, 4):
def f(i):
return lambda:i*i
fs.append(f(i))
return fs
2019-08-16
def format_name(s):
return s[0:1].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0:1].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2019-08-15
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2019-08-15
import math
def is_sqr(x):
a = int(math.sqrt(x))
return a*a == x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
a = int(math.sqrt(x))
return a*a == x
print filter(is_sqr, range(1, 101))
2019-08-14
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
2019-08-14
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2019-08-14
最新回答 / 小臭蛋
可以看下setattr的函数定义:>>> help( setattr)Help on built-in function setattr in module builtins:setattr(obj, name, value, /) Sets the named attribute on the given object to the specified value. setattr(x, 'y', v) is equivalent to ``x.y = v''
2019-08-11
import math
def is_sqr(x):
return (math.sqrt(x)%1 ==0)
print filter(is_sqr, range(1, 101))
返回平方根后除以1余数为0的值也可以达到目的
def is_sqr(x):
return (math.sqrt(x)%1 ==0)
print filter(is_sqr, range(1, 101))
返回平方根后除以1余数为0的值也可以达到目的
2019-08-08