Python Programming

Mathematical Function in Python

In Programming, Python by Baqir Ali

Just like other languages python also provides some built-in arithmetic functions that help us write mathematical formulas. These functions are in python’s cmath module. These functions lie in math module, so before using math function do import math module.

Some usefull functions are given below

FunctionsDescription
ceil(x)It returns the ceiling of x. the smallest integer greater than or equal to x.
abs(-x)It converts to a positive number
factorial(x)It returns the factorial of x
floor(x)It returns the floor of x, the largest integer less than or equal to x.
sqrt(x)It returns the square root of x
remainder(x,y)It returns the remainder of x with respect to y.

Ceiling function in Python

import math
val=2.5
print(math.ceil(val))

Output:

3

Floor function in Python

import math
val=2.5
print(math.floor(val))

Output:

2

Factorial function in Python

import math
val=5
print(math.factorial(val))

Output:

120

Square Root function in Python

import math
val=25
print(math.sqrt(val))

Output:

5.0

Support us by sharing this post