Python闭包Closure

前端之家收集整理的这篇文章主要介绍了Python闭包Closure前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Python的闭包和Python的内部函数

1 Python内部函数

def out(x): def inner(y): return "inner use % s" % y return inner(x) print out("jeapedu")

在out里定义了1个inner函数,out的返回值是调用inner(x)的值


2 python的闭包Closure

def closure(x): def inner(y): return "closure use %s %s" % (x,y) return inner print closure("Hello ")("智普教育 www.jeapedu.com")

closure里定义了函数inner,但closure的返回值是inner函数名。

请注意调用closure时后有两个实参列表!

猜你在找的PHP相关文章