The math.log() function returns the  logarithm of a given number to the specified base.

Syntax:
math.log(x, base) 

Where, x is the argument to which the logarithm is to be found.  The optional base argument specifies the  base of the  logarithm.

If the base is not given, the function returns the natural logarithm( to the base of e) of the given number.

ExampleEdit & Run
import math
print(math.log(7)) 
print(math.log(27))
print(math.log(math.pi))
Output:
1.94591014905531323.2958368660043291.1447298858494002[Finished in 0.010993574047461152s]

Examples With Base Given

ExampleEdit & Run
import math

print(math.log(8, 2))
print(math.log(100, 2))
print(math.log(64, 10))
print(math.log(100, 10))
Output:
3.06.6438561897747251.80617997398388692.0[Finished in 0.010171021800488234s]

A logarithm is the power to which a number must be raised to get some other number. Since a negative number cannot be expressed as a power of a positive base, the logarithm of a negative number is undefined .  A ValueError is raised if the argument given  to math.log() function is negative. 

ExampleEdit & Run
import math

math.log(-2)
Output:
Traceback (most recent call last):  File "<string>", line 3, in <module>ValueError: math domain error[Finished in 0.011667452054098248s]