In this lesson, you’ll learn about new and improved math
and statistics
functions in Python 3.8. Python 3.8 brings many improvements to existing standard library packages and modules. math
in the standard library has a few new functions
. math.prod()
works similarly to the built-in sum()
, but for multiplicative products:
>>> import math
>>> math.prod((2, 8, 7, 7))
784
>>> 2 * 8 * 7 * 7
784
The two statements are equivalent. prod()
will be easier to use when you already have the factors stored in an iterable.
Another new function is math.isqrt()
. You can use isqrt()
to find the integer part of square roots:
>>> import math
>>> math.isqrt(9)
3
>>> math.sqrt(9)
3.0
>>> math.isqrt(15)
3
>>> math.sqrt(15)
3.872983346207417