Skip to content
Tutorial Gateway
  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • MySQL
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
    • Search
Python LOG Function

Python log

The Python math log function calculates the logarithmic value of a given number with base E. The syntax of the log Function is

math.log(number, base);

The base argument is an optional one. If you omit this, the Python log function considers default E as a logarithm base. However, you can change it using this parameter.

Number: A valid numerical expression.

  • If the number argument is a positive number, it returns the output.
  • If the number is Negative or Zero, it returns ValueError.
  • And if it is not a number, it returns TypeError.

Python log Function Example

The log Function calculates the logarithmic value of the given number with base E. Here, we used this method to find the logarithmic value of different data types.

import math

Tup = (1, 2, 3, -4 , 5) # Tuple Declaration
Lis = [-1, 2, -3.5, -4 , 5] # List Declaration

print('Logarithm value of Positive Number = %.2f' %math.log(1))
print('Logarithm value of Positive Decimal = %.2f' %math.log(2.5))

print('Logarithm value of Tuple Item = %.2f' %math.log(Tup[2]))
print('Logarithm value of List Item = %.2f' %math.log(Lis[4]))

print('Logarithm value of Multiple Number = %.2f' %math.log(2 + 7 - 5))
print('Logarithm value of String Number = ', math.log('Hello'))
Python LOG Function
  1. Within the first two statements, we used the math log Function directly on Positive integer and Decimal values.
  2. Next two statements, We used the math Function on Tuple and List items. If you observe the above Python screenshot, this Math function is working perfectly on them.
  3. We tried it directly on multiple values.
  4. We tried the logarithmic Function on the String value, and it returns TypeError: a float is required.
  5. Next, We tried it on a Negative value, and it is returning ValueError: math domain error.
  6. Last, We tried it on Zero value. As we said before, this is returning ValueError: math domain error.
Back to Categories Python
Python factorial
Python log10

Related Topics

  • Arithmetic Operators
  • Assignment
  • Bitwise
  • Comparison
  • Logical
  • If Statement
  • If Else
  • elif Statement
  • Nested If
  • For Loop
  • while Loop
  • break Statement
  • continue
  • Dictionary
  • datetime
  • String
  • Set Object
  • Tuple Object
  • List Object
  • List Comprehensions
  • lambda
  • Functions Introduction
  • Types of Funcs
  • Iterator
  • File Handling
  • Directory
  • Class
  • classmethod
  • Inheritance
  • Method Overriding
  • static method
  • Connect to SQL Server
  • len method
  • max method
  • map method
  • print method
  • sort method
  • range
  • zip method
  • math methods
  • String methods
  • List methods
  • NumPy Array
  • np random array
  • np concatenate
  • np Array shape
  • pandas DataFrame
  • DataFrame plot
  • Series
  • matplotlib Histogram
  • matplotlib Scatter Plot
  • matplotlib Pie Chart
  • matplotlib Bar Chart
  • List length
  • List sort
  • String Concatenation
  • String Length
  • substring
  • split String
  • String format
  • String replace
  • Program Examples
  Copyright © 2023. All Rights Reserved.
Home | About | Contact | Privacy Policy