使用Python记录功能

在本文中,我们将学习Python 3.x中的Log函数。或更早。在这里,我们将观察到不同形式的日志值将具有不同的基础。现在,让我们讨论有关在Python标准库中使用日志功能的信息。

以下示例说明了Python语言中可用的日志函数的不同形式。

首先,让我们看一下如何使用数学模块

>>> import math

导入后,我们可以使用math模块中的所有可用功能。

现在让我们看一下实现。

示例

import math
# log base e
print ("Natural log of 56 is : ",math.log(56))
# log base 8
print ("Log base 8 of 64 is : ",math.log(64,8))
#log base 2
print ("Log base 2 of 12 is : ",math.log2(12))
# log base 10
print ("Log base 10 of 64 is : ",math.log10(64))
# log base value+1
print ("Logarithm 5 value of 4 is : ",math.log1p)4))

输出结果

Natural log of 56 is : 4.02535169073515
Log base 8 of 64 is : 2.0
Log base 2 of 12 is : 3.584962500721156
Log base 10 of 64 is : 1.806179973983887
Logarithm 5 value of 4 is : 1.6094379124341003

日志功能时的错误处理-

当我们在日志函数中指定任何负值时,会引发错误。这是因为在数学领域中未定义的负值iis的对数。

让我们尝试为负值执行函数-

示例

import math
# log base e
print ("Natural log of 56 is : ",math.log(56))
# log base 8
print ("Log base 8 of 64 is : ",math.log(64,8))
#log base 2
print ("Log base 2 of 12 is : ",math.log2(12))
# log base 10
print ("Log base 10 of 64 is : ",math.log10(64))
# log base value+1
print ("Logarithm 5 value of 4 is : ",math.log1p)4))

结论

在本文中,我们了解了Python 3.x中Python中的Log函数。或更早