Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
TABLE 5.2 Python Number Functions

Most of these functions are pretty self-explanatory if you’re working with math. The fsum()
function may need a little more explanation, though. It sums the values in a series, but you must
specify the series as either a Python list or tuple (see Hour 8, “Using Lists and Tuples”). Here’s an
example:


>>> math.fsum([1, 2, 3])
6.0
>>>

You just put the numbers you need to sum in the list and plug that into the fsum() function.


Power and Logarithmic Functions


If you work with logarithms and exponents, the Python math module has some functions for you.
Table 5.3 shows the logarithmic functions available.


TABLE 5.3 Python Logarithmic Functions

The pow() function performs the same function as the standard ** math symbol. It’s mostly included
in Python for completeness, as the pow() function is used in many other programming languages.


Trigonometric Functions

Free download pdf