def prod(x, y):
return x+y;
print reduce(prod, [2, 4, 5, 7, 12],3330)
return x+y;
print reduce(prod, [2, 4, 5, 7, 12],3330)
2016-06-05
妹的 我就说怎么搞得越来越难了 感觉就不是在一个层次上 这样啊 我就去另外找资源学python去了
2016-06-05
def format_name(s):
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
2016-06-04
a, b = b, a + b其实就是多个变量的赋值运算,先算=右边,再赋值给左边变量:
0)a=0,b=1
1)a=b=1,b=a+b=1
2)a=b=1,b=a+b=2
3)a=b=2,b=a+b=3
4)a=b=3,b=a+b=5
5)a=b=5,b=a+b=8
6)a=b=8,b=a+b=13
7)a=b=13,b=a+b=21
8)a=b=21,b=a+b=34
9)a=b=34,b=a+b=55
0)a=0,b=1
1)a=b=1,b=a+b=1
2)a=b=1,b=a+b=2
3)a=b=2,b=a+b=3
4)a=b=3,b=a+b=5
5)a=b=5,b=a+b=8
6)a=b=8,b=a+b=13
7)a=b=13,b=a+b=21
8)a=b=21,b=a+b=34
9)a=b=34,b=a+b=55
2016-06-04
和js的闭包一个意思
def count():
fs = []
for i in range(1, 4):
def ff(i):
def g():
return i*i
return g
fs.append(ff(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
def count():
fs = []
for i in range(1, 4):
def ff(i):
def g():
return i*i
return g
fs.append(ff(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2016-06-04
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-06-03