Python Math Functions and Math Module
gocourse.in Maintenance

We'll be back soon

Our CDN (cdn.gocourse.in) is currently unreachable. Some images, JavaScript, or CSS files may not load properly.

Estimated downtime: ~30 minutes

Python Math Functions and Math Module

Kishore V


Python Math Functions and Math Module

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

Built-in Math Functions

Finding Minimum and Maximum Values

The min() and max() functions help you quickly determine the smallest and largest values from a collection of numbers.

Example: Find the minimum and maximum values from a set of numbers.

Minimum value: 7 Maximum value: 89

Absolute Value

The abs() function converts a negative number into its positive form, while positive numbers remain unchanged.

Example: Get the absolute value of a number.

Absolute value: 15.8

Power Function

The pow() function raises a number to a specified power.

Example: Calculate 3 raised to the power of 4.

Power result: 81

Python Math Module

For more complex mathematical calculations, Python provides the math module. To access its features, you must import it first.

Syntax: import math

Square Root Calculation

The math.sqrt() function returns the square root of a number.

Square root: 9.0

Rounding Numbers

  • math.ceil() rounds a number up to the nearest integer.
  • math.floor() rounds a number down to the nearest integer.
Ceil value: 7 Floor value: 6

Mathematical Constant π (Pi)

The math.pi constant provides an accurate value of π (pi), commonly used in geometry and trigonometry.

Area of circle: 78.53981633974483

Our website uses cookies to enhance your experience. Learn More
Accept !