builtinsfilter(iterable, func):过滤func返回布尔否值元素enumerate(iterable):添加索引迭代zip(*iterables):打包迭代元素map(func, *iterables):func接受各迭代器中元素作为
参数调用(类似zip)iter:两种产生迭代器的模式iter(iterable):返回迭代器iter(callable, sentinel):调用callable直到返回
sentinel停止迭代(不包括)while循环itertoolsitertools:包含为高效循环而创建迭代器的函数
count(start, step=1):步长累加cycle(p):循环p中元素repeat(elem, n=None):重复elemaccumulate(p, func=None):累加p中元素chain(*iters):链接迭代器chain.from_iterable(iterable):链接可迭代对象中迭代器compress(data, selelctors):根据selectors选取datadropwhile(pred, seq):保留首个满足pred之后所有元素takewhile(pred, seq):保留首个不满足pred之前元素filterfalse(pred, seq):反filtergroupby(iterable, key=None):根据key(v)值分组迭代器islice(seq, start=0, stop=None, step=1):切片starmap(func, seq):迭代对seq中执行func(*elem)tee(iterable, n=2):复制迭代器,默认2个zip_longes(*iters, fillvalue):依最长迭代器zip,较短
循环填充或fillvalue填充product(*iters, repeat=1):笛卡尔积permutations(p, r=None):r长度的排列,缺省全排列combinations(p, r):r长度组合combinations_with_replacement(p,r):可重复组合functoolsfunctools:包含高阶函数,即参数、返回值为其他函数的函数
cmp_to_key(func):将旧式比较函数转换新式key function
key参数中转换旧式比较函数sortedminmaxheapq.nlargestheapq.nsmallestitertools.groupby
- key function:接收参数,返回可以用于排序的值
partial(func, *args, **kwargs):返回partial对象,其
调用时类似使用args、kwargs调用func
partial.method(func, *args, **kwargs):适合类命名空间
中函数、描述器
update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS, udpated=WRAPPER_UPDATES):
更新wrapper函数信息为wrapped函数信息
reduce(func, iterable[, initializer]):使用func接受
两个参数,reduce处理iterable@lru_cache(maxsize=128, typed=False):缓存函数执行结果
- 可以用于方便实现动态规划
@singledispatch:转换函数为单分派范型函数,实现python
的重载(接口多态)
- single dispatch:单分派,基于单个参数类型分派的 范型函数分派形式
@wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES):
等价于partial(update_wrapper, wrapped, assigned, updated)
@total_ordering:根据类中已定义比较方法实现剩余方法__eq__、其他富比较方法中任意一种operatoroperator:提供与python内置运算符对应的高效率函数
lt(a,b)/__lt__(a,b)le(a,b)eq(a,b)ne(a,b)ge(a,b)gt(a,b)not(obj)truth(obj):等价于使用bool构造器is_(a,b)is_not(a,b)add(a,b)sub(a,b)mul(a,b)div(a,b)pow(a,b)mod(a,b)floordiv(a,b)truediv(a,b)matmul(a,b)abs(obj)neg(obj)pos(obj)
- 在位运算对可变数据类型才会更新参数,否则只返回结果
iadd(a,b):等价于a += bisub(a,b)imul(a,b)idiv(a,b)ipow(a,b)imod(a,b)ifloordiv(a,b)itruediv(a,b)imatmul(a,b)and_(a,b)or_(a,b)xor(a,b)inv(obj)/invert(obj)lshift(a,b)shift(a,b)iand(a,b)ior(a,b)ixor(a,b)index(a)concat(a,b)contains(a,b)countOf(a,b)delitem(a,b)getitem(a,b)indexOf(a,b)setitem(a,b,c)length_hint(obj, default=0)attrgetter(attr)/attrgetter(*attrs):返回函数,函数
返回值为参数属性attritemgetter(item)/itemgetter(*items):类似methodcaller(name[, args...]):类似mode="r"/"w"/"a"/"+"/"t"/"b"
t:文本,可省略b:二进制r:读,默认w:写a:追加,大部分支持+:更新模式,同时允许读写r+:文件已存在,读、写w+:清除之前内容,读、写a+:读、追加写rt/rbuffering/bufsize = -1/0/1/int
0:不缓冲,只在二进制模式中被运行1:逐行缓冲,只在文本模式中有效-1:全缓冲io.DEFAULT_BUFFER_SIZE查询.isatty()),逐行缓冲-1encoding(str)
utf-8utf-16utf-16-leutf-16-beutf-32gbxxxxlocale.getpreferedencoding()返回值block/blocking = True/False
True(阻塞)raise Exceptiontimeout = None/num
block=False时,一般timeout参数设置无效fn/func/callable(callable)
args = ()/None/tuple/list/*args(arg_1, ...)
()/None,无参数kwrags/kwds = {}/None/dict/**kwargs(kwarg_1=v1, ...)
{}/None,无参数callback=callable
None,无参数chunksize=None/1/int
chunksize
能减少进程间通信消耗,但会降低灵活性None/1,一次传递一个元素daemon=False/None/True
-c:解释执行语句-u:强制输入、输出流无缓冲,直接输入,默认全缓冲