The Python math library is a built-in module that provides access to a wide range of mathematical functions and constants, making it essential for scientific computing, data analysis, and engineering applications.

Key Features

  • Built-in and No Installation Required: The math module is part of Python’s standard library, so you don’t need to install it separately. Simply import it using:

    import math
  • Common Constants:

    • math.pi: Returns the value of π (3.141592653589793).

    • math.e: Returns Euler’s number (2.718281828459045).

  • Core Mathematical Functions:

    • Trigonometry: math.sin(), math.cos(), math.tan(), and their inverse/hyperbolic variants (asin, acosh, etc.).

    • Logarithms: math.log(), math.log10(), math.log2(), and math.log1p() for precise computation near zero.

    • Exponentials: math.exp(), math.pow(), and math.expm1() for accurate results with small values.

    • Rounding: math.ceil(), math.floor(), math.trunc(), and math.isclose() for comparing floating-point numbers.

    • Roots & Powers: math.sqrt(), math.pow(), and math.isqrt() for integer square roots.

    • Factorial: math.factorial(n) computes the factorial of a non-negative integer.

    • GCD & LCM: math.gcd(a, b) and math.lcm(*integers) for number theory tasks.

    • Miscellaneous: math.fabs(), math.fsum(), math.dist(), math.comb(), math.perm().

Usage Example

import math

# Calculate area of a circle
radius = 5
area = math.pi * math.pow(radius, 2)
print(f"Area: {area}")

# Compute factorial
print(f"Factorial of 5: {math.factorial(5)}")

# Convert degrees to radians and compute sine
angle_deg = 45
angle_rad = math.radians(angle_deg)
print(f"Sin(45°): {math.sin(angle_rad)}")

Best Practices

  • Use from math import sqrt, pi to avoid prefixing every function call.

  • Always check input validity (e.g., math.sqrt() raises ValueError for negative numbers).

  • For array-based operations, consider using NumPy instead of math for better performance.

The math module is reliable, efficient, and ideal for precise mathematical computations in Python.

🌐
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
3 weeks ago - This module provides access to common mathematical functions and constants, including those defined by the C standard. These functions cannot be used with complex numbers; use the functions of the ...
🌐
W3Schools
w3schools.com › python › module_math.asp
Python math Module
Python has a built-in module that you can use for mathematical tasks.
🌐
W3Schools
w3schools.com › python › ref_math_log.asp
Python math.log() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... # Import math Library import math # Return the natural logarithm of different numbers print(math.log(2.7183)) print(math.log(2)) print(math.log(1)) Try it Yourself »
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-math.html
Python Math
The + operator, will do the right thing at run time when it comes across the complex value. This is the sort of informal flexibility you get with Python, where it looks at the type of each value at run time. The regular math module does not work with complex numbers, e.g.
🌐
Svitla Systems
svitla.com › home › articles › python libraries math, scipy, numpy, matplotlib
Python Libraries: Math, SciPy, NumPy & Matplotlib
November 11, 2025 - If you are developing a program in Python to perform certain tasks, you need to work with trigonometric functions, as well as complex numbers. Although you cannot use these functions directly, you can access them by turning on the math module math, which gives access to hyperbolic, trigonometric and logarithmic functions for real numbers. To use complex numbers, you can use the math module cmath. When comparing math vs numpy, a math library is more lightweight and can be used for extensive computation as well.
Price   $$$
Address   100 Meadowcreek Drive, Suite 102, 94925, Corte Madera
🌐
Quora
quora.com › Why-does-Python-use-modules-such-as-math-Wouldnt-it-be-simpler-to-just-have-the-functions-available-without-importing-them
Why does Python use modules such as math? Wouldn't it be simpler to just have the functions available without importing them? - Quora
Grouping related functionality (math, os, json, datetime) makes the standard library easier to learn and browse. Module names communicate purpose and intent; math.sqrt clearly signals a mathematical s ... Python groups functions like sin, cos, ...
🌐
W3Schools
w3schools.com › python › python_math.asp
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.
🌐
Tutorialspoint
tutorialspoint.com › python › python_maths.htm
Python - math Module
The math module is a built-in module in Python that is used for performing mathematical operations. This module provides various built-in methods for performing different mathematical tasks.
Find elsewhere
🌐
Brilliant
brilliant.org › courses
Courses | Brilliant
Guided interactive problem solving that’s effective and fun. Try thousands of interactive lessons in math, programming, data analysis, AI, science, and more.
🌐
GitHub
github.com › wilsonfreitas › awesome-quant
GitHub - wilsonfreitas/awesome-quant: A curated list of insanely awesome libraries, packages and resources for Quants (Quantitative Finance) · GitHub
3 weeks ago - sympy - SymPy is a Python library for symbolic mathematics.
Starred by 24.9K users
Forked by 3.3K users
Languages   Jupyter Notebook 59.0% | Python 40.9% | CSS 0.1%
🌐
CodeHS
codehs.com › tutorial › ryan › math-module-in-python
Tutorial: Math Module in Python | CodeHS
Click on one of our programs below to get started coding in the sandbox
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-math-module
Python Math Module - GeeksforGeeks
July 26, 2025 - The math module in Python is a built-in library that contains a collection of mathematical functions and constants.
🌐
Real Python
realpython.com › courses › exploring-python-math-module
Exploring the Python math Module – Real Python
January 25, 2023 - In this step-by-step course, you’ll learn all about Python’s math module for higher-level mathematical functions. Whether you’re working on a scientific project, a financial application, or any other type of programming endeavor, you just can’t escape the need for math!
🌐
Mimo
mimo.org › glossary › python › math-module
Python Math Module: Syntax, Usage, and Examples
The Python math module provides a set of mathematical functions and constants that simplify calculations in programming. It includes functions for arithmetic, trigonometry, logarithms, and more. This module is useful for scientific computing, data analysis, and engineering applications.
🌐
Stack Abuse
stackabuse.com › the-python-math-library
The Python Math Library
August 15, 2023 - The Python Math Library provides us access to some common math functions and constants in Python, which we can use throughout our code for more complex mathematical computations. The library is a built-in Python module, therefore you don't have to do any installation to use it.
🌐
Oreate AI
oreateai.com › blog › using-the-python-math-library › 94ea511280b114a7317c948f320cbb8b
Using the Python Math Library - Oreate AI Blog
December 22, 2025 - The Python math library is imported using 'import math'. After importing the math module, we can use hundreds of built-in mathematical functions and constants to perform calculations such as: - Square roots, absolute values, trigonometric functions ...
🌐
Real Python
realpython.com › ref › stdlib › math
math | Python Standard Library – Real Python
The Python math module provides a comprehensive collection of mathematical functions and constants, making it a go-to tool for performing mathematical operations in Python.
🌐
GitHub
github.com › python › cpython › blob › main › Modules › mathmodule.c
cpython/Modules/mathmodule.c at main · python/cpython
/* Math module -- standard C math library functions, pi and e */ ... For #1, raise OverflowError. ... For #3 and #4, raise ValueError. It may have made sense to raise · Python's ZeroDivisionError in #3, but historically that's only been
Author   python
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
3 weeks ago - Take two (non-complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using integer division. With mixed operand types, the rules for binary arithmetic operators apply. For integers, the result is the same as (a // b, a % b). For floating-point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that.