Python 3 math Module Functions

By Hemanta Sundaray on 2021-09-10

Learn about the built-in Python functions for working with numbers in my blog post here.

First, import the math module near the top of the .py file or Jupyter cell to make the functions available to the rest of the code.

Learn how to work with modules and the import statement in my blog post here.

math.ceil(x)

Returns the smallest integer greater than or equal to x.

import math

print(math.ceil(-3.4))
# -3

math.floor(x)

Returns the largest integer less than or equal to x.

import math

print(math.floor(-3.4))
# -4

math.pow(x, y)

Returns x raised to the power y.

import math

print(math.pow(3, 4))
# 81.0

math.sqrt(x)

Gets the square root of x.

import math

print(math.sqrt(81))
# 9.0

Join the Newsletter