Python的内置函数实例(1)

#!/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,如需转载请自行联系原作者

上一篇:云拨测助力节卡机器人 全面优化海外网站性能


下一篇:《Docker技术入门与实战》——3.6 存出和载入镜像