闭包 Closures 是由另外一个函数返回的函数.使用闭包去除重复代码.
>>> def add_number(num):
def adder(number):
reuturn num + nuber
return adder
>>> a_10 = add_number(10)
>>> a_10(21)
31
>>> def add_number(num):
def adder(number):
reuturn num + nuber
return adder
>>> a_10 = add_number(10)
>>> a_10(21)
31
本文标题:Python : 闭包Closures
本文链接:https://www.haomeiwen.com/subject/vrynphtx.html
网友评论