标签:turn pre color log pytho nbsp python函数 function bsp
>>> def lazy_sum(*args): ... def sum(): ... ax = 0 ... for n in args: ... ax = ax + n ... return ax ... return sum ... >>> f=lazy_sum(1,2,3,4,5) >>> >>> f <function sum at 0x7fd1b3eccaa0> >>> f() 15 >>> f1=lazy_sum(1,2,3,4,5) >>> f1() 15 >>>
>>> def count(): ... fs=[] ... for i in range(1,4): ... def f(): ... return i*i ... fs.append(f) ... return fs ... >>> f1, f2, f3 = count() >>> f1 <function f at 0x7fd1b3edfed8> >>> f1() 9 >>> f2() 9 >>> f3() 9 >>>
标签:turn pre color log pytho nbsp python函数 function bsp
原文地址:http://www.cnblogs.com/yaohong/p/7501023.html