The Python LOG function is one of the Python Math function which is used to calculate the logarithmic value of given number with base E. In this article we will show you, How to use LOG() function in Python Programming language with example.

## Syntax of a Python LOG Function

The basic syntax of the LOG Function in Python Programming Language is as shown below:

Math.log(number, base);

**Base: **This is an optional argument. If you omit this argument, LOG() function will consider default E as logarithm base but you can change the value using this parameter.

**Number:** It can be a number or a valid numerical expression.

- If the
*number*argument is positive number, LOG() function will return the output. - If the
*number*argument is Negative number, LOG() function will return**ValueError** - If the
*number*argument is not a number, LOG() function will return**TypeError.** - If the
*number*argument is, LOG() function will return**Zero****ValueError**

### Python LOG Function Example

The Python LOG Function is used to calculate the logarithmic value of given number with base E. In this example, We are going to check the same with different data types and display the output

**PYTHON CODE**

# Python LOG Function 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'))

**OUTPUT**

**ANALYSIS**

- At the beginning, We declared Python List and Tuple with some random values.
- Within the first two statements, We used the LOG() Function directly on Positive integer and Decimal values.
- Next two statements, We used the LOG() Function on Python Tuple and List items. If you observe the above screenshot, LOG() function is working perfectly on them.
- Next statement, We tried LOG() Function directly on multiple values
- Next statement, We tried LOG() Function on String value. As we said before, this will return TypeError: a float is required as output
- Next, We tried LOG() Function on Negative value. As we said before, this is returning ValueError: math domain error as output
- Last, We tried LOG() Function on Zero value. As we said before, this is returning ValueError: math domain error as output

Thank You for Visiting Our Blog