Fiveable

🐍Intro to Python Programming Unit 2 Review

QR code for Intro to Python Programming practice questions

2.6 The math module

2.6 The math module

Written by the Fiveable Content Team • Last updated August 2025
Written by the Fiveable Content Team • Last updated August 2025
🐍Intro to Python Programming
Unit & Topic Study Guides

Python's math module is a powerful tool for mathematical operations. It offers a wide range of functions and constants beyond basic arithmetic, enabling complex calculations in scientific and engineering applications.

From trigonometry to logarithms, the math module enhances Python's mathematical capabilities. It provides precise constants like pi and e, and functions for advanced operations, making it essential for solving numerical problems efficiently.

Math Module

Built-in vs math module functions

Built-in functions readily available in Python without importing any modules (abs(), round(), min(), max(), pow()). Math module functions require importing the math module: import math provide additional mathematical functions and constants (math.sqrt(), math.sin(), math.log(), math.pi, math.e). Use math module functions when dealing with trigonometric functions (sin(), cos(), tan()), performing logarithmic or exponential calculations (log(), exp()), or requiring mathematical constants like pi (π\pi) or e. Use built-in functions for basic arithmetic and rounding operations (such as round(), ceil(), and floor()).

Built-in vs math module functions, Python

Math module for numerical problems

Constants in the math module include math.pi, the mathematical constant pi (π3.141592653589793\pi \approx 3.141592653589793), and math.e, the mathematical constant e (Euler's number, e2.718281828459045e \approx 2.718281828459045). The math module provides various mathematical constants for precise calculations. Functions in the math module: math.sqrt(x) returns the square root of x math.pow(x, y) returns x raised to the power of y math.exp(x) returns e raised to the power of x math.log(x[, base]) returns the logarithm of x to the given base (default is natural logarithm, base e) Trigonometric functions: math.sin(x), math.cos(x), math.tan(x) accept angles in radians Inverse trigonometric functions: math.asin(x), math.acos(x), math.atan(x) return angles in radians

Example usage:

</>Python
import math

# Calculate the area of a circle with radius 5
area = math.pi * math.pow(5, 2)
print(area)  # Output: 78.53981633974483

log_value = math.log(100, 10) print(log_value) # Output: 2.0

</>Code

 ###### ![fiveable_print_image_2](https://fiveable.me)

### Degree-radian conversion with math module
Angle units: degrees commonly used in everyday life (0° to 360°) and radians used in mathematical calculations (0 to 2$$\pi$$). Converting between degrees and radians:
  `math.radians(x)` converts angle x from degrees to radians
  `math.degrees(x)` converts angle x from radians to degrees

Conversion formulas:
  Degrees to radians: $$radians = degrees \times \frac{\pi}{180}$$
  Radians to degrees: $$degrees = radians \times \frac{180}{\pi}$$

Example usage:
```python
import math

# Convert 45 degrees to radians
angle_rad = math.radians(45)
print(angle_rad)  # Output: 0.7853981633974483

# Convert pi/4 radians to degrees
angle_deg = math.degrees(math.pi/4)
print(angle_deg)  # Output: 45.0

Advanced Mathematical Functions

The math module provides a range of functions for more complex mathematical operations:

  • Logarithmic functions: math.log(), math.log10(), math.log2() for natural, base-10, and base-2 logarithms
  • Exponential functions: math.exp(), math.expm1() for e^x and e^x - 1
  • Trigonometric functions: math.sin(), math.cos(), math.tan(), and their inverse functions
  • Hyperbolic functions: math.sinh(), math.cosh(), math.tanh(), and their inverse functions

These functions are essential for various applications in scientific computing and numerical analysis.

Pep mascot
Upgrade your Fiveable account to print any study guide

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Click below to go to billing portal → update your plan → choose Yearly → and select "Fiveable Share Plan". Only pay the difference

Plan is open to all students, teachers, parents, etc
Pep mascot
Upgrade your Fiveable account to export vocabulary

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Plan is open to all students, teachers, parents, etc
report an error
description

screenshots help us find and fix the issue faster (optional)

add screenshot

2,589 studying →