Python Math
Python Math
Dark mode
Dark code
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP BOOTSTRAP HOW TO W3.CSS C C++ C# REACT R JQUERY DJANGO
Python Casting
Python Strings ADVERTISEMENT
Python Booleans
Python Operators
Python Lists
Python Tuples
Python Sets
Python Dictionaries
Python Math
Python If...Else
❮ Previous Next ❯
Python While Loops
Python For Loops
Python Functions
Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical
Python Lambda
tasks on numbers.
Python Arrays
Python Classes/Objects
Python Inheritance
Python Iterators
Built-in Math Functions
Python Polymorphism
The min() and max() functions can be used to find the lowest or highest value in an iterable:
Python Scope
Python Modules
Python Dates
Example Get your own Python Server
Python Math
Python JSON x = min(5, 10, 25)
Python RegEx y = max(5, 10, 25)
Python PIP
Python Try...Except print(x)
Python User Input print(y)
Try it Yourself »
The abs() function returns the absolute (positive) value of the specified number:
Example
x = abs(-7.25)
print(x)
COLOR PICKER
Try it Yourself »
Example
Return the value of 4 to the power of 3 (same as 4 * 4 * 4):
x = pow(4, 3)
print(x)
Try it Yourself »
ADVERTISEMENT
import math
When you have imported the math module, you can start using methods and constants of the module.
ADVERTISEMENT
The math.sqrt() method for example, returns the square root of a number:
Example
import math
x = math.sqrt(64)
print(x)
Try it 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
import math
x = math.ceil(1.4)
y = math.floor(1.4)
print(x) # returns 2
print(y) # returns 1
Try it Yourself »
Example
import math
x = math.pi
print(x)
Try it Yourself »
ADVERTISEMENT
ADVERTISEMENT
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.