Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
wb_sunny

# Python math Module

Python math module helps the user to get direct access to the mathematical functions in their program. Thus, it helps to solve and minimize complex computations.

In order to avail the functionalities of the math module, we need to import it in our code using `import math` statement.

The math module does not support Complex datatypes. The `cmath` module serves the functionality for the complex data types.

## Python Math Trigonometric functions

The below code represents some of the trigonometric functions of the math module.

Example:

```import math

angle_degree = 60

```

Output:

## Python Math Power and Logarithmic Functions

The below code represents some of the logarithmic functions of the math module.

Example:

```import math
print('The value of 2^2: ' + str(math.pow(2, 2)))
print('Square root of 121: ' + str(math.sqrt(121)))
print('The value of 8^e: ' + str(math.exp(8)))
print('The value of Log(625) with base 5: ' + str(math.log(625, 5)))
print('The value of Log(444) with base 2: ' + str(math.log2(444)))
print('The value of Log(1000) with base 10: ' + str(math.log10(1000)))
```

Output:

## Python Math Numeric Representation Functions

The below code represents some of the numeric functions of the math module.

Example:

```import math

input = 12.35
print('The Floor value of the given input: ' + str(math.floor(input)))

print('The Ceil value of the given input: ' + str(math.ceil(input)))

a = 20
b = -10

print('The value of a after copying the sign from b: ' + str(math.copysign(a, b)))

s1 = -25
s2 = 25

print('Absolute value of s1 and s2: ' + str(math.fabs(s1)) + ', ' + str(math.fabs(s2)))

my_input = [0,1,2,3,4,5,6,7,8,9,-1]
print('Sum of the elements of the list: ' + str(math.fsum(my_input)))

p = float('nan')
if math.isnan(p):
print('It is not a number')
q = float('inf')
y = 10
if math.isinf(q):
print('It is Infinity')
print(math.isfinite(q)) #q is not a finite number
print(math.isfinite(y)) #y is a finite number
```

Output:

## Python Math PI

Python math module provides a constant called pi that can be used in mathematical computations, eg: area of a circle.

Example:

```import math

print('Value of pi: ', math.pi)

print('Area of Circle: ', math.pi * (radius ** 2))
```

Output:

`Value of pi: 3.141592653589793Area of Circle: 12.566370614359172`

## Conclusion

Thus, in this article, we have implemented most of the functionalities offered by the math module in Python.