Quick Introduction to Python Math Module

In this article you will learn about Python math module.

Python Math Module – Before moving ahead, let’s know a little bit about Python Arithmetic Operator

Module math – Python has a built-in function of named math. This math module used on objects related to mathematical problems.

Import math – To use Python built-in math function, import module named math.

math.sqrt() – It returns the square root of a number.

Example 1- Import module math and get square root of number 5.

import math
x = math.sqrt(25)
 
print(x) 
python-math-module

Explanation – As it is shown clearly that function sqrt() returned square root of 25. 

Example 2- Import modul math and get pi value.

import math
x = math.pi
 
print(x) 
python-math-module

Explanation – As it is shown clearly that function pi returned the pi value. 

math.ceil() – It returns the nearest upward number of an integer.

Example 3- Import math to return nearest upward number of integer.

import math
x = math.ceil(7.8)

print(x)
python-math-module

Explanation – As it is shown clearly that function ceil returned the nearest greater number of given number.

math.floor() – It returns the nearest downward number of an integer.

Example 4- Import math to return nearest downward number of integer.

import math
x = math.floor(7.8)

print(x)
python-math-module

Explanation – As it is shown clearly that function ceil returned the nearest lowest number of given number.

min() function – It returns the most lowest number from the given numbers.

Example 5- It returns the most-lowest number from given number.

x = min(1,2,3)
print(x)
python-math-module

Explanation – As it is shown clearly that function min() returned the lowest number from given numbers.

max() function – It returns the most highest number from the given numbers.

Example 6- It returns the most-highest number from given number.

x = max(1,2,3)
print(x)
python-math-module

Explanation – As it is shown clearly that function max() returned the highest number from given numbers.

abs() function – It returns the absolute (positive) value of the specified number.

Example 7- Use of abs() function to return the

x = abs(-4.3)
print(x)
python-math-module

Explanation – As it is shown clearly that function abs() returned the absolutely positive number from given number.

pow( x, y) function – It returns the value of x to the power of y (xy).

Example 8- Use of pow(x,y) function to return the power of 10 (10*10).

x = pow(10, 2)
print(x)
python-math-module

Explanation – As it is shown clearly that function pow() returned the power of 10. In other words, left operand (100) is multiplied till the number of right operand (2) and returned 100.

If you find anything incorrect in the above-discussed topic and have any further questions, please comment down below.

Like us on

1 thought on “Quick Introduction to Python Math Module”

Leave a Comment

Stay in the loop

codingstreets