In Python, logarithmic functions are provided by the math module, which offers various functions to calculate logarithms for different bases.
Common Log Functions:
1. math.log(x, base): Returns the logarithm of x to the specified base. If the base is not specified, it defaults to e (natural logarithm).
python
import math
print(math.log(10, 2)) # Logarithm of 10 base 2
print(math.log(10)) # Natural logarithm of 10
2. math.log10(x): Returns the base-10 logarithm of x.
python
print(math.log10(100)) # Output: 2.0
3. math.log2(x): Returns the base-2 logarithm of x.
python
print(math.log2(8)) # Output: 3.0
4. math.exp(x): Returns e raised to the power of x (inverse of natural logarithm).
python
print(math.exp(1)) # Output: 2.718281828459045 (approx. value of e)
These functions are useful for mathematical computations involving exponential growth, data transformations, and scientific calculations.