Ben*_*lan 1 python math vscode-debugger
第 7 行有一个等于 0 的变量 x。当我运行程序时,如果 x 不大于 0,它不应该前进到下一个缩进。但由于某种原因它确实如此。
到底是怎么回事?
class MyProblem():
def __init__(self):
self.x = 5
def recursive(self):
self.x -= 1
if self.x > 0:
self.recursive()
p = MyProblem()
p.recursive()
Run Code Online (Sandbox Code Playgroud)
self.recursive()您看到调试器在is 0 时突出显示该行的原因self.x是因为它正在弹出调用堆栈:回想一下,您在 was x5, 4, 3, 2, 1 时输入了此递归函数。一旦x达到 0,您会看到调试器离开1、2、3、4 和 5 的递归函数,这就是为什么踩到那条线会让你停留在同一行。