函数:

def fact(n):

  if n==1:

    return 1

  return n * fact(n-1)

递归过程:

print(fact(5))

>>fact(5)

>>5 * fact (4)

>>5 * (4 * fact(3))

>>5 * (4 * (3 * fact(2)))

>>5 * (4 * (3 * (2 * fact(1))))

>>5 * (4 * (3 * (2 * 1)))

>>5 * (4 * (3 * 2))

>>5 * (4 * 6)

>>5 * 24

>>120

05-11 09:23