functools.partial

其实就是简单的闭包,函数式编程的思想。可以理解成绑定了一部分参数的函数。作用就是少传参数,更短,更简洁。

import functools

def add(a, b):

    return a + b

add(1, 2)

3

plus3 = functools.partial(add, 1)

plus5 = functools.partial(add, 2)

plus3(2)
3

plus5(1)

3

 

posted @ 2015-08-12 23:07  沐风先生  阅读(79)  评论(0编辑  收藏  举报