Standard Library
Python math Module
Python Mathematical Functions
Python math module provides functions like sin and pi constants.
Overview of the Python math Module
The Python math
module is part of the standard library and provides mathematical functions defined by the C standard. It is widely used for performing complex mathematical operations with ease. The module includes various functions, constants, and types that facilitate mathematical computations.
Importing the math Module
To use the functions and constants provided by the math
module, you must first import it into your Python script. This can be done using the following line of code:
Commonly Used math Functions
The math
module provides a variety of functions for mathematical operations. Below are some of the most commonly used functions:
math.sqrt(x)
: Returns the square root ofx
.math.sin(x)
: Returns the sine ofx
radians.math.cos(x)
: Returns the cosine ofx
radians.math.tan(x)
: Returns the tangent ofx
radians.math.log(x, base)
: Returns the logarithm ofx
to the specifiedbase
. If no base is provided, returns the natural logarithm.
Common Constants in math Module
In addition to functions, the math
module also provides several useful mathematical constants:
math.pi
: The mathematical constant π (pi), approximately equal to 3.14159.math.e
: The mathematical constant e, approximately equal to 2.71828.
Using Trigonometric Functions
The math
module provides trigonometric functions that operate on radians. To convert degrees to radians, you can use math.radians()
. These functions are useful for various applications, including engineering and physics.
Standard Library
- datetime Module
- math Module
- random Module
- os Module
- sys Module
- json Module
- re Module
- time Module
- collections Module
- itertools Module
- argparse Module
- logging Module
- urllib Module
- shutil Module
- glob Module
- statistics Module
- calendar Module
- zipfile Module
- pickle Module
- threading Module
- subprocess Module
- Requests Module
- cMath Module
- Previous
- datetime Module
- Next
- random Module