关于修饰符问题
def test3(func):print('继续测试')
func()
return 0, 1
@test3
def second():
for i in range(10):
print(i)
为什么这段代码会直接运行
def test3(func):
print('继续测试')
func()
return 0, 1
@test3
def second():
for i in range(10):
print(i)
print(second())
这段代码运行报错
Traceback (most recent call last):
File "D:\练习\练习!!.py", line 9, in <module>
print(second())
TypeError: 'tuple' object is not callable 应该把 return 0, 1 改成 return func
def test3(func):
print('继续测试')
func()
return func
@test3
def second():
for i in range(10):
print(i)
print(second())
页:
[1]