def is_sqr(x):
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
2018-02-09
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))
2018-02-08
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])
2018-02-08
def format_name(L):
return L[0:1].upper() + L[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return L[0:1].upper() + L[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2018-02-08
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)
2018-02-08
def calc_prod(lst):
def calc_prod():
prod=1
for x in lst:
prod=prod*x
return prod
return calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
def calc_prod():
prod=1
for x in lst:
prod=prod*x
return prod
return calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
2018-02-08
def cmp_ignore_case(s1, s2):
if s1[0].lower()<s2[0].lower():
return -1
else:
return 1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].lower()<s2[0].lower():
return -1
else:
return 1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-02-08
最新回答 / 裴翔
交互环境下可以定义函数,书写的时候注意符号 “:”和缩进就好。定义好的函数可以直接在下一行使用。对于.py文件中的函数,就是用import进来,然后就可以调用了。。。。
2018-02-07
class Student(Person):
#__slots__ = ('score')
def __init__(self,name,gender,score,**kw):
super(Student,self).__init__(name,gender)
self.score=score
for k,v in kw.items():
setattr(self,k,v)
s = Student('Bob', 'male', 99,sss='sss')
print s.score
print s.sss
#__slots__ = ('score')
def __init__(self,name,gender,score,**kw):
super(Student,self).__init__(name,gender)
self.score=score
for k,v in kw.items():
setattr(self,k,v)
s = Student('Bob', 'male', 99,sss='sss')
print s.score
print s.sss
2018-02-07
已采纳回答 / 为彭十七加油oO
这个里面区别主要是:在第一个方法里面 def f(j): def g(): return j*j return g r = f(i) fs.append(r)中的那个return g,是返回了一个对象g,这时候他还...
2018-02-07