# map()和reduce()函数用法的深入了解,高阶函数
#map()函数接受两个参数,一个函数本身和一个序列
def n(x):
return x*x
a = map(n, [1,2,3,4,5])
print 'map()函数接受两个参数,一个函数本身和一个序列:'
print 'a = map(n, [1,2,3,4,5])'
print a
#reduce()函数用法也是接受两个参数,其效果reduce(f, [x1, x2, x3, x4]) = f(f(f(x1, x2), x3), x4)
def add(x,y):
return x+y
'用reduce()函数求和例子'
a = reduce(add,[1,2,3,4,5,6])
print '用reduce()函数求和例子'
print a
add.__doc__
#python内置list排序函数sorted()
a= [3,5,7,13,42,123,23,1,'liwei',6,11,53]
print sorted(a)
#----------------------------------------------------------------------
def story(**kwds):
""""""
return 'this is indsa'\
'kuweu %(job)s casewr %(name)s' %kwds
print story(name='liwei',job='age')
python 学习笔记(六)
最新推荐文章于 2023-08-20 18:05:52 发布