I have a question, why python numeric calculation is very fast? for example the below code runs shorter than one second
import math
print math.factorial(10000)
why???
factorial() in Python Finding the factorial of a number is a frequent requirement in data analysis and other mathematical analysis involving python. The factorial is always found for a positive integer by multiplying all the integers starting from 1 till the given number.
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math. factorial() function returns the factorial of desired number. Syntax: math.
The factorial of a number is the number that you get after multiplying all numbers from 1 to that number. The factorial of a number is denoted by the '! ' symbol.
Python is a very powerful programming tool and can be used for a wide variety of use cases in real life. It offers a direct function that can compute the factorial of a given number without writing the code explicitly.
The math
module's functions are implemented in C:
It provides access to the mathematical functions defined by the C standard.
By using an efficient algorithm in C, you get fast results.
If you are asking why this particular operation is so fast, then see Why is math.factorial much slower in Python 2.x than 3.x? and the C code itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With