Recursion

Also from books


def fact(x):
    if x == 1:
        return 1
    else:
        return x * fact(x-1) #Recursion is calculating factorial

fact (3)> 6 # 3 * 2 * 1 = 6 3! Factorial calculation

By calling fact (3) return x * fact(x-1) # 3 x 2 Immediately called fact (2) return x * fact(x-1) # (3*2) x 1 Factorial calculation like (I think it's an image of stacking like a stack)

Recommended Posts

Recursion
Merge sort using recursion