CKTIS / Python
math.log
Computes a natural logarithm or a logarithm to the specified base.
Version: Python 3.14; repository image, production runtime not attested
Syntax
math.log(x[, base])Computes a natural logarithm or a logarithm to the specified base.
One has logarithm zero for every admissible base. Real arguments must be positive.
A logarithm answers which exponent raises the base to x. The example uses 3⁴ = 81 and e⁰ = 1. The base defaults to e. For finite real inputs x and base must be positive; a nonpositive value raises ValueError and base 1 causes ZeroDivisionError.
import math
assert math.log(81, 3) == 4.0 and math.log(1) == 0.0
assert math.log(0.25, 0.5) == 2.0
Examples
import math
print(math.log(81, 3))
print(math.log(1))
Result
4.0 0.0
A logarithm answers which exponent raises the base to x. The example uses 3⁴ = 81 and e⁰ = 1. The base defaults to e. For finite real inputs x and base must be positive; a nonpositive value raises ValueError and base 1 causes ZeroDivisionError.