Introduction Variables Data Types Numbers Casting Strings Boolean Operators Lists Tuples Dictionaries If-Else While Loops For Loops Functions Arrays Scope Modules User Input File Handling Python Maths

Welcome to the lesson on Python Maths

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:

Example:

syntax
Try it out yourself

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

syntax

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

Example: Return the value of 4 to the power of 3 (same as 4 * 4 * 4):

syntax
Try it out yourself

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:

import math

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:

Example:

syntax
Try it out yourself

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:

Example:

syntax
Try it out yourself

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

Example:

syntax
Try it out yourself

End of Python Maths

You have learned Python Maths in simple terms.

This concludes the end of our tutorials.

Thank you for learning python from StudyPython!

Back To Top