《笨办法学Python》(29)---partial function 偏函数,部分函数

版权声明:一起学习,一起成长,欢迎关注犀牛先生的博客 https://blog.csdn.net/xuemanqianshan/article/details/85256119

偏函数(自己写)

(1)也是高阶函数

(2)利用其它函数,锁定部分参数,生成新函数

(3) 返回其他函数

>>> def int2(a):
    return int(a,base=2)
>>> int2("100101")
37

functiontools模块 partial偏函数(系统模块自带)

>>> import functools
>>> int8=functools.partial(int,base=8)
>>> int8("102012")
33802
>>> 

>>> max_with100=functools.partial(max,100)
>>> max_with100(1,5,55,71)
100

猜你喜欢

转载自blog.csdn.net/xuemanqianshan/article/details/85256119