Top 10 math functions in python

Photo by Annie Spratt on Unsplash

The math module provides us various functions. Some of them are discussed in this article. Import the math function to begin.

import math

The ten methods in this article are

  1. ceil and floor
  2. factorial
  3. gcd
  4. sqrt
  5. pow
  6. sin, cos, tan
  7. exp
  8. fabs
  9. isclose
  10. constants

Ceil and floor functions

The ceil() method returns an integer that is greater than or equal to the given float value. Similarly, the floor() method returns an integer that is lesser or equal to the given float value. If an integer value is given the same value is returned.

floor function


This method returns the factorial value of a number. In mathematics, the factorial of a positive integer n, denoted by n! is the product of all positive integers less than or equal to n.

Example 4! is 4*3*2*1 and 5! is 5*4*3*2*1

factorial method


The gcd() method returns the gcd of the two numbers passed to the function. In mathematics, the greatest common divisor (gcd) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4.

gcd method


The sqrt() method returns the square root of a number. In mathematics, a square root of a number x is a number y such that y² = x.

sqrt method


The pow(x, y) method returns the value of x raised to the power of y. The return type is always float and hence takes both integer or float as arguments.

pow method

sin, cos, and tan

The sin, cos, and tan methods take a degree and return their corresponding value.

sin, cos and tan methods


Return e raised to the power x, where e = 2.718281… is the base of natural logarithms.

exp method


The fabs() method returns the absolute value of the number as a floating-point value. This is similar to the abs() method except for the result here is in float.

fabs method


The isclose() method takes two values. We can specify the value of the difference. A difference value greater than this returns False and a difference value less than this returns True. By default, the difference value is 0.

The difference value can be specified as a relative or absolute difference.

isclose method

The first command returns false as the difference between 2 and 5 is 3, but the difference that we have specified is 1.

Whereas the second command returns true as the difference between 2 and 3 is 1, which matches our difference.


The values of mathematical constants such as π, Τ, and e are also available in the math module.

math constants


Hope these methods helped you. Happy coding!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Allwin Raju

Allwin Raju

Python Developer | Django Developer | Python Enthusiast