Eventually the value of x reaches 0 (because of the x-1 instruction) and stops calling itself (the factorial of 0 is defined as 1).
The whole function is also explained in the second link in my first answer. You can also write the function as:
def factor(x):
result = 1
while x > 0:
result = x * result
x = x - 1
return result