#!/usr/bin/python
# -*- coding=utf-8 -*-
def sum(x,y):
return x+y
print apply(sum,(1,6))
def usefilter(k):
if(k>0) and (k%2 == 0):
return k
print filter(usefilter,range(-100,100))
def usereduce(a,b):
return a+b
print reduce(usereduce,range(1,7))
def usemap(a,b):
return a*b
print map(usemap,range(1,7),range(7,1,-1))
运行结果:
7
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98]
21
[7, 12, 15, 16, 15, 12]
本文转sinojelly51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/363754,如需转载请自行联系原作者