Python Intro - Functools Usage
2017-02-23 11:22
363 查看
#!/usr/bin/python
import getopt, sys, urllib, time
import os
from functools import *
from array import *
def add(x, y): return x+y
def f1(x): return x % 2 == 0 and x % 3 == 0
def f2(x): return x * x
def f3(x):
x0 = 0
x1 = 1
if(x <= 0): return 0
else:
if(x == 1): return 1
for i in range(2, x + 1):
y = x0 + x1
x0 = x1
x1 = y
return y
def main(argv):
aaa=array('i', [1,2,3,4,5,6,7,8,9,10])
for i in aaa:
print(i)
ab = reduce(add, aaa)
print(ab)
ab = filter(f1, range(1, 10))
for i in ab:
print(i)
a=f3(int(argv[0]))
print(a)
#-------------------------------
if __name__ == "__main__":
main(sys.argv[1:])
import getopt, sys, urllib, time
import os
from functools import *
from array import *
def add(x, y): return x+y
def f1(x): return x % 2 == 0 and x % 3 == 0
def f2(x): return x * x
def f3(x):
x0 = 0
x1 = 1
if(x <= 0): return 0
else:
if(x == 1): return 1
for i in range(2, x + 1):
y = x0 + x1
x0 = x1
x1 = y
return y
def main(argv):
aaa=array('i', [1,2,3,4,5,6,7,8,9,10])
for i in aaa:
print(i)
ab = reduce(add, aaa)
print(ab)
ab = filter(f1, range(1, 10))
for i in ab:
print(i)
a=f3(int(argv[0]))
print(a)
#-------------------------------
if __name__ == "__main__":
main(sys.argv[1:])
相关文章推荐
- python--functools的使用
- 【python】偏函数 functools partial
- Python-进阶-functools模块小结
- python 9-2 如何为被装饰的函数保存元数据,使用标准库functools中的装饰器wraps 装饰内部包裹函数
- 【Python模块】functools —— 作用于可调用对象的高阶函数集合
- Python functools
- python 理解functools.wraps
- python. partial应用from functools import partial
- python学习代码笔记(map,reduce,filter,sort,decorator,functools.partial)
- Python 装饰器之 functools.wraps
- python的functools.partial用法解释
- python的functools.partial用法解释
- Python技巧——list comprehension 与 functools.reduce
- python学习笔记2-functools.wraps 装饰器
- Python中functools模块的常用函数解析
- Python functools.partial
- python 装饰器及标准库functools中的wraps
- Python 入门:装饰器(decorator)、@functools.wraps、@staticmethod、@classmethod
- 用Python functools.wraps实现装饰器
- Python提供了以下几个内置tools模块:operator collections itertools functools