Hi @marinero2015 ,
This line, inside the function definition, implements the recursive case, in which the function calls itself ...
return x * factorial(x-1)
Provided that a function is defined by the time a call of that function is executed, that call is permissible.
When the Python interpreter first encounters that recursive line of code, the function is still only partially defined. However, that is fine, because the recursive call does not execute until the function definition has been completely processed by the Python interpreter, and you invoke the function by calling it from the outside.
Once the definition is complete, you finally cause the function to execute with this line, and all goes well ...
In summary, the
factorial function is allowed to call itself because by the time the call is actually executed, the
factorial function definition has been completed, and there is no need to use the version from the