A quick note on some useful updates made to standard Python maths support. does for +. It was added at Python 3.8.
>>> math.prod([3, 4, 5])
60
>>> math.prod([])
1
Added in 3.9, , an empty list of arguments returns 1. Extended in 3.9, the related function now supports n-dimensional points, and .
I also wanted to mention a nice extension to the power function; in this case to the builtin remains as it was. Builtin :
… If mod is present and exp is negative, base must be relatively prime to mod. In that case, pow(inv_base, -exp, mod) is returned, where inv_base is an inverse to base modulo mod.
Here’s an example of computing an inverse for 38 modulo 97:
>>> pow(38, -1, mod=97)
23
>>> 23 * 38 % 97 == 1
True
SOCIAL SHARE CARD GENERATOR