闭包和内嵌函数课后题
def funOut():def funIn():
print('宾果!你成功访问到我啦!')
return funIn
为什么这里直接用funOut()无法得到“宾果!你成功访问到我啦”,funOut()()就可以啊 >>> def o():
def i():
print('哈哈哈')
return i
>>> o()
<function o.<locals>.i at 0x0000018DB17C9700>
>>> o()()
哈哈哈
>>> help(o)
Help on function o in module __main__:
o()
>>> help(o())
Help on function i in module __main__:
i()
>>> help(o()())
哈哈哈
Help on NoneType object:
class NoneType(object)
|Methods defined here:
|
|__bool__(self, /)
| self != 0
|
|__repr__(self, /)
| Return repr(self).
|
|----------------------------------------------------------------------
|Static methods defined here:
|
|__new__(*args, **kwargs) from builtins.type
| Create and return a new object.See help(type) for accurate signature.
照着写,然后用心品味一下出现的文字{:10_256:} 函数名 返回地址函数名() 获取值
函数的正确调用方式:函数名()
>>> def test():
return 8
>>> test
<function test at 0x0000000002B53AE8>
>>> test()
8
所以你这里是:
funOut() 得 funIn的地址
funOut()() 才得 funIn函数的值
你懂了?
页:
[1]