🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Python Notes
Topic #93

Python Math


Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers.


Built-in Math Functions

The min() and max() functions can be used to find the lowest or highest value in an iterable:

Example

    x = min(5, 10, 25)
y = max(5, 10, 25)

print(x)
print(y)

The abs() function returns the absolute (positive) value of the specified number:

Example

    x = abs(-7.25)

print(x)

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

Example

    x = pow(4, 3)

print(x)

The Math Module

Python has also a built-in module called math, which extends the list of mathematical functions.

To use it, you must import the math module:

import math

When you have imported the math module, you can start using methods and constants of the module.

The math.sqrt() method for example, returns the square root of a number:

Example

    import
    math

x = math.sqrt(64)

print(x)

The math.ceil() method rounds a number upwards to its nearest integer, and the math.floor() method rounds a number downwards to its nearest integer, and returns the result:

Example

    import
    math

x = math.ceil(1.4)
y = math.floor(1.4)

print(x) #
    returns 2
print(y) # returns 1

The math.pi constant, returns the value of PI (3.14...):

Example

    import
    math

x = math.pi

print(x)

Complete Math Module Reference

In our Math Module Reference you will find a complete reference of all methods and constants that belongs to the Math module.

Want to go beyond the notes?

Join CodingNow 2.0's Python course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Python Math – FAQs

Quick answers about learning Python Math in Python.

This free note from CodingNow 2.0 explains Python Math in Python — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Python topic on CodingNow 2.0, including Python Math, is 100% free with no signup required.
With focused practice, most students grasp Python Math in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now