To understand recursion, you must first understand recursion.
Imo, a the best way to wrap you head around any recursive function is to write down (like on paper, old-school style) what is happening in some form.
Why use paper? It's easier and faster to draw random stuff than on a computer. This one is fairly simple, but with more complicated recursion it may be impractical to write everything out explicitly. In those cases, I like to summarize stuff symbolically, draw diagrams etc.
Second best is to make it print stuff in a small example. To do that, let's modify your initial code a bit.
def hanoi(n,_from,,t):
print(f"Hanoi called: n:{n}, f:{f}, v:{v}, t:{t}")
if n == 0:
pass
else:
hanoi(n-1,f,t,v)
print(f"Move disc from {f} to {t}. n:{n}")
hanoi(n-1,v,f,t)
hanoi(3,"a","b","c")
The output yields:
Hanoi called: n:3, f:a, v:b, t:c (4)
Hanoi called: n:2, f:a, v:c, t:b (2)
Hanoi called: n:1, f:a, v:b, t:c (1)
Move disc from a to c. n:1 (1)
Move disc from a to b. n:2 (2)
Hanoi called: n:1, f:c, v:a, t:b (3)
Move disc from c to b. n:1 (3)
Move disc from a to c. n:3 (4)
Hanoi called: n:2, f:b, v:a, t:c (6)
Hanoi called: n:1, f:b, v:c, t:a (5)
Move disc from b to a. n:1 (5)
Move disc from b to c. n:2 (6)
Hanoi called: n:1, f:a, v:b, t:c (7)
Move disc from a to c. n:1 (7)
Process finished with exit code 0
If you then compare this to this 
Notice how your first call, not satisfying the base condition (n==0) continues to "drill down" into the recursion. Once the base case is reached, then the recursion unstacks the calls - you move out from the LAST recursive call (n==1, the first move disk). Then n==2 (the 2nd move disk) etc....
Perhaps not so ironically, the tower of Hanoi itself is a pretty good analogy for how recursion works: you essentially stack calls (e.g. what you're eventually going to do) into a big pile. Then once you're done stacking new calls (e.g. you've reached your base case, n==0 here) then you pick up whatever call was last put onto you callstack & execute that.
EDIT: I've removed the n==0 calls to Hanoi (since they don't do anything and just confuse stuff). I've added in parenthese the step in the image that corresponds to each call on the image (2), (3), etc.... Each # will be present twice - once when we execute it (e.g. "move disk from...") and once when we put onto our callstack ("Hanoi called....").
As you can see, when we have a call to Hanoi with a n>1 number, a few of those calls will be stacked (say (1) (2) (4) ). When we get to n==0, we'll unstack those gradually. So we do a --> c first, which is (1), because that call was stacked onto the recursion stack last. E.g. (4) with n==3 was added first, but before we could execute it the recursion forced us to stack another with n==2 (2), and n==1 (1). Only at that point could we start to execute our backlog of calls to Hanoi. We'll get as to why the very first call to Hanoi is labelled (4) and not (3) just below. Just make sure you get this first part right.
Then we do a ---> b (which is (2) ) right after. But at that point n==2, so when we do that call to Hanoi, before we proceed with (4), we add another call on the stack (3). Since that one was added last, we unstack (3) right away. Then the only call we have left to pop from the callstack is (4). Since its n==3, that will bring us to add to more new calls on the recursion stack, (6) and (5). Again, we unstack them in the opposite order (since (5) is "on top" of (6) ). With (6), n==2, so we'll add another call to Hanoi, which will be (7). At that point, we don't add anymore calls to the stack, so we get out of the recursion completely.
if n:
or saferif n <= 0:
– Klaus D. Dec 8 '19 at 1:33