Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
math module
math

What is the math module in Python?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The math module is a built-in Python library. It helps in numerous mathematical functions following the C standard.

This works for real numbers only.

svg viewer

Basic functions

Functions Description
math.ceil( value ) It returns the smallest integer greater than or equal to value.
math.copysign( value1,value2 ) It returns the float with magnitude of value1 and sign of value2.
math.fabs( value ) It returns the absolute of value.
math.factorial( value ) It returns the factorial of value.
math.floor( value ) It returns the largest integer greater than or equal to value.
math.fsum( iterable ) It returns the float sum of the values of the iterable.

Examples

# Importing Math library.
import math
#ceiling function
print(math.ceil(10.555))
#factorial function
print(math.factorial(3))

Other functions

LogarithmicTrigonometricPi constantExponentialPowerSquare Root

There are numerous other functions as well:

  • Logarithmic function: Returns the natural logarithm of a specified number.
  • Exponential function: Returns a float number after raising e to a specified number.
  • Square root function: Returns the square root of a specified number.
# Importing Math library.
import math
# tangent function
print(math.atan(90))
# power function
print(math.pow(3,2))
# pi constant
print(math.pi)

RELATED TAGS

python
math module
math
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring