log10(): Base-10 Logarithm Calculation

math.log10(x) returns log of input number x with base 10
import math
print(math.log10(2))  # 0.3010299956639812
print(math.log10(4))  # 0.6020599913279624
print(math.log10(5))  # 0.6989700043360189
Using negative number
For any value less than or equal to 0 , we will get ValueError
import math
print(math.log10(-2))
print(math.log10(0))
Above code will generate error.

Comparison with Other Log Functions:

Example: Compare base 10, base e, and base 2 logarithms.
import math
num = 1000
print("log10(1000):", math.log10(num))  # Base 10 log :Output 3.0
print("log(1000):", math.log(num))      # Base e log :6.907755278982137
print("log2(1000):", math.log2(num))    # Base 2 log : 9.965784284662087
Scientific Notation:
Example: Logarithms to find magnitude.
richter_scale = math.log10(1000)
print(f"Richter scale magnitude: {richter_scale}")
Output
Richter scale magnitude: 3.0

Example 1: Calculating Base-10 Logarithm

Basic usage of `log10()` with positive numbers.
import math
print(math.log10(100))  # Output: 2.0
print(math.log10(1000)) # Output: 3.0

Example 2: Error Handling for Negative or Zero Values

Demonstrates error handling with `try-except` for values less than or equal to zero.
import math
try:
    print(math.log10(-10))
except ValueError as e:
    print("Error:", e)
Output:
Error: math domain error

Example 3: Calculating Logarithm in Data Normalization

Logarithmic transformation to reduce skew in a dataset.
data = [1, 10, 100, 1000, 10000]
log_data = [math.log10(x) for x in data]
print(log_data)
Output:
[0.0, 1.0, 2.0, 3.0, 4.0]

Applications of log10()

  • Data Transformation: Used in data preprocessing to normalize or reduce data skew.
  • Scientific Calculations: Common in calculating pH values, sound intensity (dB), and earthquake magnitude (Richter scale).
  • Logarithmic Scaling: Helpful in visualizing data across a wide range, such as in histograms or charts.

log2 log1p() log()

Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer