|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def add(func):
- def inner():
- x = func()
- return x + 1
- return inner
-
- def cube(func):
- def inner():
- x = func()
- return x * x * x
- return inner
-
- def square(func):
- def inner():
- x = func()
- return x * x
- return inner
-
- @add
- @cube
- @square
- ##def test():
- ## return 2
- def test01(a):
- return a
-
- print(test01(a=8))
复制代码
请教大牛,为什么我在最后把test()的内容改掉会报错呢?
报错如下:
- Traceback (most recent call last):
- File "D:/Program Files/Python37/test/1025-3.py", line 27, in <module>
- print(test01(a=8))
- TypeError: inner() got an unexpected keyword argument 'a'
复制代码
本帖最后由 jackz007 于 2022-10-25 11:20 编辑
- def add(func):
- def inner(p):
- x = func(p) # 调用的是 cube() . inner()
- return x + 1 # 返回 262144 + 1 = 262145
- return inner
-
- def cube(func):
- def inner(p):
- x = func(p) # 调用的是 square() . inner()
- return x * x * x # 返回 64 * 64 * 64 = 262144
- return inner
-
- def square(func):
- def inner(p):
- x = func(p) # 调用的是 test01()
- return x * x # 返回 8 * 8 = 64
- return inner
- @add
- @cube
- @square
- ##def test():
- ## return 2
- def test01(a):
- return a
-
- print(test01(8)) # 打印 262145
复制代码
|
|