The factorial method in Python
Now, we are going to learn about the factorial method in relation to the math module. As the name of the method says, the factorial method returns the factorial of the given argument number. So, whenever we need to get the factorial of some number, we can simply use the factorial method. Remember that we need to import the math module so that we can make use of the factorial method.
Let’s have a look at a simple program, which demonstrates the same thing.
Python Math Factorial
As you can see in the above program, we have imported the math module, and then we are calling the factorial method. We are passing the number 5 as an argument to the factorial method. So, the factorial method returns the factorial of the given number. So, if we try to run the above program, we can say that the output comes out to be 120. if we are giving some non-integral value, or some negative number to the method, then it raises ValueError. You can try giving some invalid argument.
So, as and when required, we can make use of the factorial method from the math module. Remember that the factorial method returns the factorial of the given number. If we give some non-integral argument or a negative number as an argument, then it raises a ValueError.