Python Glossary Русский

all Python 3mathterm

math.log10

logarithms

Returns the base-10 logarithm. More accurate than math.log(x, 10). Used for orders of magnitude.

Syntax

math.log10(x)

Zero and negative inputs raise ValueError ("math domain error") rather than returning -inf. Integers too large to convert to float are still accepted — where float(n) already raises OverflowError — but the answer is an approximation. So counting digits with int(math.log10(n)) + 1 is fragile right at powers of ten; len(str(n)) is exact.

Examples

import math
print(math.log10(1))      # → 0.0
print(math.log10(10))     # → 1.0
print(math.log10(100))    # → 2.0
print(math.log10(1000))   # → 3.0
print(math.log10(0.001))  # → -3.0
print(math.log10(2))      # → 0.30102...

See also

Open in the full glossarydocs.python.orgReport an inaccuracy