Discuss / Python / 小白求解,关于返回值的问题。

小白求解,关于返回值的问题。

Topic source

JLeo0420

#1 Created at ... [Delete] [Delete and Lock User]

def log(text): def decorator(func): def wrapper(args, **kw): print('%s %s():' % (text, func.name)) return func(args, **kw) return wrapper return decorator 以上的两个return 后面都是返回到内部的函数,这不是构成死循环吗?如何去理解函数执行的顺序? 希望高手能够解答

是先返回函数的,所以首先返回的是decorator的函数,然后又返回了wrapper这个函数,最后又返回了原函数。


  • 1

Reply