Open links in new tab
  1. Python provides a built-in module called math that offers a wide range of mathematical functions and constants. This module is essential for performing various mathematical operations, from basic arithmetic to complex trigonometric calculations.

    Basic Usage

    To use the math module, you need to import it first:

    import math
    Copied!

    Common Functions

    Here are some commonly used functions in the math module:

    • math.ceil(x): Returns the smallest integer greater than or equal to x.

    • math.floor(x): Returns the largest integer less than or equal to x.

    • math.fabs(x): Returns the absolute value of x.

    • math.factorial(x): Returns the factorial of x.

    • math.gcd(x, y): Returns the greatest common divisor of x and y.

    • math.sqrt(x): Returns the square root of x.

    • math.pow(x, y): Returns x raised to the power of y.

    • math.log(x, base): Returns the logarithm of x to the specified base.

    Example:

    import math

    print(math.ceil(2.3)) # Output: 3
    print(math.floor(2.3)) # Output: 2
    print(math.fabs(-10)) # Output: 10.0
    print(math.factorial(5)) # Output: 120
    print(math.gcd(15, 5)) # Output: 5
    print(math.sqrt(16)) # Output: 4.0
    print(math.pow(2, 3)) # Output: 8.0
    print(math.log(8, 2)) # Output: 3.0
    Copied!
  1. Python math Module - W3Schools

    50 rows · Learn how to use the built-in math module in Python for various mathematical tasks. The …

  2. Python Math Module - GeeksforGeeks

    Jul 26, 2025 · The math module in Python is a built-in library that contains a collection of mathematical functions and constants. It is commonly used to perform standard math operations such as rounding, …

  3. math | Python Standard Library – Real Python

    In this step-by-step tutorial, you’ll learn all about Python’s math module for higher-level mathematical functions. Whether you’re working on a scientific project, a …

  4. Master Python's Math Module for Math Functions

    May 10, 2025 · Learn how to use Python's math module for basic and advanced math operations. It provides functions for square roots, powers, trigonometry, …

  5. Math Module in Python | PythonForAll

    Feb 9, 2026 · Learn how to use Python's built-in math module for mathematical computations.

  6. Python - math Module - Online Tutorials Library

    Learn how to use the math module in Python for performing mathematical operations. The module provides various methods for trigonometric, logarithmic, …

  7. Python Math Functions and Math Module - gocourse.in

    Python provides several built-in mathematical functions for basic calculations. For advanced mathematical operations, Python also includes a powerful math module.

  8. Python math Module Tutorial – Functions, Examples, and Usage

    Learn the Python math module with examples of sqrt, pow, ceil, floor, sin, cos, log, and more. Beginner-friendly guide with functions explained.

  9. Python math Module - TutorialsTeacher.com

    Learn how to use the math module in Python to perform various mathematical operations and calculations. The module provides functions for trigonometry, logarithms, exponents, powers, roots, …

  10. People also ask
    Loading
    Unable to load answer