有人可以向我解释这段代码是如何执行的吗?我仍然搞砸了递归

Some one can explain to me how this code executes ? I still mess up with recursion

输出应该是 4,3,2,1 对吧?

def test(x): 
 if x > 0 :
  test(x - 1)
  print(x)
test(4)
#output => 1
#output => 2
#output => 3
#output => 4

这就是调用堆栈。代码被推送到调用堆栈并在我们进行时弹出。这是完成递归调用的地方。参考这个 https://www.freecodecamp.org/news/how-recursion-works-explained-with-flowcharts-and-a-video-de61f40cb7f9/

test(4) 正在生成test(3)、test(2)、test(1),并推送到调用堆栈。众所周知,Stack 是 FILO(先进后出)。最后推送的递归指令将弹出并执行第一个结果打印 1. 然后是 2,3 最后是 4.