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 Python log Function is shown below.

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 Python 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

  • Python Tutorial
  • Python Operators
    • Download and Install Python
    • Arithmetic Operators
    • Assignment Operators
    • Bitwise Operators
    • Comparison Operators
    • Logical Operators
  • Python If Else & Loops
    • If Else Statement
    • elif Statement
    • Nested If Statement
    • For Loop
    • While Loop
    • Break Statement
    • Continue Statement
  • Python Object Types
    • Dictionary
    • datetime
    • Iterator
    • List
    • List Comprehensions
    • lambda
    • String
    • Sets
    • Tuple
    • Functions & Types
    • File Handling
    • Directory
  • Python Common Functions
    • len method
    • max method
    • map method
    • print method
    • range method
    • sort method
    • zip method
  • Python OOPS
    • Class
    • classmethod
    • Inheritance
    • Method Overriding
    • static method
  • Python SQL Server
    • Connect Python to SQL Server
    • Create Database
    • Select Statement
    • Select Top N records
    • Order By Clause
    • Where Clause
  • Python math Functions
    • Introduction to math library
    • ceil Function
    • copysign Function
    • degrees Function
    • fabs Function
    • factorial Function
    • floor Function
    • fmod Function
    • frexp Function
    • fsum Function
    • gamma Function
    • gcd Function
    • isfinite Function
    • isinf Function
    • isnan Function
    • lgamma Function
    • radians Function
    • round Function
    • ldexp Function
    • trunc Function
  • Python Log Functions
    • exp method
    • expm1 method
    • log method
    • log2 method
    • log10 method
    • pow method
    • sqrt method
  • Python Trigonometric Func
    • cos method
    • cosh method
    • acos method
    • acosh method
    • sin method
    • sinh method
    • asin method
    • asinh method
    • tan method
    • tanh method
    • atan method
    • atan2 method
    • atanh method
  • Python String Functions
    • Introduce String methods
    • capitalize Function
    • casefold Function
    • center Function
    • count Function
    • endswith Function
    • find String
    • format String
    • index Function
    • isalpha Function
    • isalnum Function
    • isdecimal Function
    • isdigit Function
    • isnumeric Function
    • isspace Function
    • isupper Function
    • islower Function
    • join Strings
    • ljust Function
    • lower Function
    • lstrip Function
    • partition string
    • replace string
    • rfind Function
    • rindex Function
    • rjust Function
    • rpartition
    • rsplit string
    • strip string
    • startswith
    • split String
    • swapcase string
    • title Function
    • upper Function
  • Python List Functions
    • Introduction to List Functions
    • List append Function
    • List copy Function
    • List clear Function
    • List del Function
    • List extend Function
    • List insert Function
    • List index Function
    • List length Function
    • List pop Function
    • List remove Function
    • List sort Function
  • Python Dictionary Functions
    • Introduction to dict Functions
    • Dictionary copy function
    • Dictionary clear Function
    • Dictionary fromkeys
    • Dictionary get Function
    • Dictionary items
    • Dictionary keys function
    • Dictionary len function
    • Dictionary popitem
    • Dictionary pop function
    • Dictionary setdefault
    • Dictionary update
    • Dictionary values
  • Python Set Functions
    • Introduction to set Functions
    • set add
    • set copy
    • set discard
    • set len
    • set min
    • set max
    • set pop
    • set remove
    • set sorted
    • set union
  • Python Working on Dates
    • strftime
    • strptime
    • timedelta
  • Python Numpy Module
    • numpy array
    • numpy array shape
    • numpy Aggregate Functions
    • numpy Arithmetic Operations
    • numpy Bitwise operators
    • numpy Exponential Functions
    • numpy Comparison Operators
    • numpy logical operators
    • numpy String Functions
    • numpy Trigonometric Functions
    • numpy concatenate array
    • numpy random array
    • numpy random rand
    • numpy random randint
    • numpy random randn
    • Random Number Generator
  • Python Numpy Functions
    • numpy array add
    • numpy average
    • numpy degrees
    • numpy digitize
    • numpy logspace
    • numpy prod
    • numpy max
    • numpy min
    • numpy radians
    • numpy sum
    • numpy tile
  • pandas & matplotlib
    • pandas DataFrame
    • pandas DataFrame plot
    • pandas Series
    • Convert Dictionary to DataFrame
    • Convert List to DataFrame
    • matplotlib Histogram
    • matplotlib Scatter Plot
    • matplotlib Pie Chart
    • matplotlib Bar Chart
  • Python FAQs
    • String Concatenation
    • String Length
    • substring
    • Dictionary copy Vs = Operator
  • Program Examples
  Copyright © 2023. All Rights Reserved.
Home | About | Contact | Privacy Policy