Python Tutorials · Python Math

Python Math

Learn all about Python Math in this comprehensive tutorial.

5 min read intermediate
  • Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers.
  • The min() and max() functions can be used to find the lowest or highest value in an iterable:
  • Python has also a built-in module called math, which extends the list of mathematical functions.
  • In our Math Module Reference you will find a complete reference of all methods and constants that belongs to the Math module.

Introduction

Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers.

Built-in Math Functions

The min() and max() functions can be used to find the lowest or highest value in an iterable:

python

The abs() function returns the absolute (positive) value of the specified number:

python

The pow(x, y) function returns the value of x to the power of y (xy).

python

The Math Module

Python has also a built-in module called math, which extends the list of mathematical functions.

To use it, you must import the math module:

python

When you have imported the math module, you can start using methods and constants of the module.

The math.sqrt() method for example, returns the square root of a number:

python

The math.ceil() method rounds a number upwards to its nearest integer, and the math.floor() method rounds a number downwards to its nearest integer, and returns the result:

python

The math.pi constant, returns the value of PI (3.14...):

python

Complete Math Module Reference

In our Math Module Reference you will find a complete reference of all methods and constants that belongs to the Math module.

Module quiz

2 questions
1

Which of the following is true about Python Math?

2

What is the most common pitfall when working with Python Math?

Answer all questions to submit.