Hello,
I realize that this may sound like a silly question, but the last time I programmed it was in assembler so my thinking may be off:
A recursive function as so:
def fac(n):
if n == 0:
return 1
else:
return n * fac(n - 1)
Why is it that when the function reaches n == 0 that it does not return 1 but rather the answer which is the factorial. I am thinking something like in assembler it would be when n == 0:
mov eax, 1
ret
Why does the code above work, I suppose python returns the last value on the stack before that condition ?