Javatpoint Logo
Javatpoint Logo

Python math module

Python math module is defined as the most popular mathematical functions, which includes trigonometric functions, representation functions, logarithmic functions, etc. Furthermore, it also defines two mathematical constants, i.e., Pie and Euler number, etc.

Pie (n): It is a well-known mathematical constant and defined as the ratio of circumstance to the diameter of a circle. Its value is 3.141592653589793.

Euler's number(e): It is defined as the base of the natural logarithmic, and its value is 2.718281828459045.

There are different math modules which are given below:

math.log()

This method returns the natural logarithm of a given number. It is calculated to the base e.

Example

Output:

log(fabs(x), base) is : -6.698970004336019

math.log10()

This method returns base 10 logarithm of the given number and called the standard logarithm.

Example

Output:

log10(x) is : 1.1139433523068367 

math.exp()

This method returns a floating-point number after raising e to the given number.

Example

Output:

The given number (x) is : 0.05
e^x (using exp() function) is : 0.05127109637602412 

math.sqrt()

This function returns the square root of any given number.

Example

Output:

sqrt of 20 is 4.47213595499958
sqrt of 14 is 3.7416573867739413
sqrt of 17.8995 is 4.230780069916185

math.expm1()

This method returns e raised to the power of any number minus 1. e is the base of natural logarithm.

Example

Output:

The given number (x) is : 0.2
e^x (using expml() function) is : 0.22140275816016985

math.cos()

It returns the cosine of any number, in radians.

Example

Output:

Given angle : 1.0471975511965976
cos(x) is : 0.5000000000000001

math.sin()

It returns the sine of any number, in radians.

Example

Output:

Given angle : 1.0471975511965976
sin(x) is : 0.8660254037844386

math.tan()

It returns the tangent of any number, in radians.

Example

Output:

Given angle : 1.0471975511965976
tan(x) is : 1.7320508075688767
Next TopicPython Tutorial




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA