import math
def is_sqr(x):
return math.sqrt(x)%1==0
print filter(is_sqr, range(1,101))
def is_sqr(x):
return math.sqrt(x)%1==0
print filter(is_sqr, range(1,101))
2016-03-29
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])
2016-03-29
def format_name(s):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2016-03-29
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)
2016-03-29
import math
def is_sqr(x):
return int(math.sqrt(x))**2 == x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return int(math.sqrt(x))**2 == x
print filter(is_sqr, range(1, 101))
2016-03-29
已采纳回答 / 数独题
import mathdef is_sqr(x): return int(math.sqrt(x))==math.sqrt(x)print filter(is_sqr, range(1, 101))is_sqr(x): 和 print filter(is_sqr, range(1, 101))中的函数看清楚
2016-03-28
>>> help(setattr)
Help on built-in function setattr in module __builtin__:
setattr(...)
setattr(object, name, value)
Set a named attribute on an object; setattr(x, 'y', v) is equivalent to
``x.y = v''.
Help on built-in function setattr in module __builtin__:
setattr(...)
setattr(object, name, value)
Set a named attribute on an object; setattr(x, 'y', v) is equivalent to
``x.y = v''.
2016-03-28