Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

Python Tutorial

Python HOME Python Intro Python Get Started Python Syntax Python Comments Python Variables Python Data Types Python Numbers Python Casting Python Strings Python Booleans Python Operators Python Lists Python Tuples Python Sets Python Dictionaries Python If...Else Python While Loops Python For Loops Python Functions Python Lambda Python Arrays Python Classes/Objects Python Inheritance Python Iterators Python Scope Python Modules Python Dates Python JSON Python RegEx Python PIP Python Try...Except Python User Input Python String Formatting

File Handling

Python File Handling Python Read Files Python Write/Create Files Python Delete Files

Python NumPy

NumPy Intro NumPy Getting Started NumPy Creating Arrays NumPy Array Indexing NumPy Array Slicing NumPy Data Types NumPy Copy vs View NumPy Array Shape NumPy Array Reshape NumPy Array Iterating NumPy Array Join NumPy Array Split NumPy Array Search NumPy Array Sort NumPy Array Filter NumPy Random NumPy ufunc

Machine Learning

Getting Started Mean Median Mode Standard Deviation Percentile Data Distribution Normal Data Distribution Scatter Plot Linear Regression Polynomial Regression Multiple Regression Scale Train/Test Decision Tree

Python MySQL

MySQL Get Started MySQL Create Database MySQL Create Table MySQL Insert MySQL Select MySQL Where MySQL Order By MySQL Delete MySQL Drop Table MySQL Update MySQL Limit MySQL Join

Python MongoDB

MongoDB Get Started MongoDB Create Database MongoDB Create Collection MongoDB Insert MongoDB Find MongoDB Query MongoDB Sort MongoDB Delete MongoDB Drop Collection MongoDB Update MongoDB Limit

Python Reference

Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary

Module Reference

Random Module Requests Module Math Module cMath Module

Python How To

Remove List Duplicates Reverse a String Add Two Numbers

Python Examples

Python Examples Python Exercises Python Quiz Python Certificate

Python math Module


Python math Module

Python has a built-in module that you can use for mathematical tasks.

The math module has a set of methods and constants.


Math Methods

Method Description
math.acos(x) Returns the arc cosine value of x
math.acosh(x) Returns the hyperbolic arc cosine of x
math.asin(x) Returns the arc sine of x
math.asinh(x) Returns the hyperbolic arc sine of x
math.atan(x) Returns the arc tangent value of x
math.atan2(y, x) Returns the arc tangent of y/x in radians
math.atanh(x) Returns the hyperbolic arctangent value of x
math.ceil(x) Rounds a number upwards to the nearest integer, and returns the result
math.comb(n, k) Returns the number of ways to choose k items from n items without repetition and order
math.copysign(x, y) Returns a float consisting of the value of the first parameter and the sign of the second parameter
math.cos(x) Returns the cosine of x
math.cosh(x) Returns the hyperbolic cosine of x
math.degrees(x) Converts an angle from radians to degrees
math.dist(p, q) Calculates the euclidean distance between two specified points (p and q), where p and q are the coordinates of that point
math.erf(x) Returns the error function of x
math.erfc(x) Returns the complementary error function of x
math.exp(x) Returns the value of Ex, where E is Euler's number (approximately 2.718281...), and x is the number passed to it
math.expm1(x) Returns the value of Ex - 1, where E is Euler's number (approximately 2.718281...), and x is the number passed to it
math.fabs(x) Returns the absolute value of a number
math.factorial() Returns the factorial of a number
math.floor(x) Rounds a number downwards to the nearest integer, and returns the result
math.fmod(x, y) Returns the remainder of specified numbers when a number is divided by another number
math.frexp() Returns the mantissa and the exponent, of a specified value
math.fsum(iterable) Returns the sum of all items in an iterable (tuples, arrays, lists, etc.)
math.gamma(x) Returns the gamma value of x
math.gcd() Returns the highest value that can divide two integers
math.hypot() Find the Euclidean distance from the origin for n inputs
math.isclose() Checks whether two values are close, or not
math.isfinite(x) Checks whether x is a finite number
math.isinf(x) Check whether x is a positive or negative infinty
math.isnan(x) Checks whether x is NaN (not a number)
math.isqrt(n) Returns the nearest integer square root of n
math.ldexp(x, i) Returns the expression x * 2i where x is mantissa and i is an exponent
math.lgamma(x) Returns the log gamma value of x
math.log(x, base) Returns the natural logarithm of a number, or the logarithm of number to base
math.log10(x) Returns the base-10 logarithm of x
math.log1p(x) Returns the natural logarithm of 1+x
math.log2(x) Returns the base-2 logarithm of x
math.perm(n, k) Returns the number of ways to choose k items from n items with order and without repetition
math.pow(x, y) Returns the value of x to the power of y
math.prod(iterable, *, start=1) Returns the product of an iterable (lists, array, tuples, etc.)
math.radians(x) Converts a degree value (x) to radians
math.remainder(x, y) Returns the closest value that can make numerator completely divisible by the denominator
math.sin(x) Returns the sine of x
math.sinh(x) Returns the hyperbolic sine of x
math.sqrt(x) Returns the square root of x
math.tan(x) Returns the tangent of x
math.tanh(x) Returns the hyperbolic tangent of x
math.trunc(x) Returns the truncated integer parts of x

Math Constants

Constant Description
math.e Returns Euler's number (2.7182...)
math.inf Returns a floating-point positive infinity
math.nan Returns a floating-point NaN (Not a Number) value
math.pi Returns PI (3.1415...)
math.tau Returns tau (6.2831...)