python独立log示例
Python math.log()方法 (Python math.log() method)
math.log() method is a library method of math module, it is used to get the natural logarithm of a given number to base e (by default). It accepts the number and a base (which an optional) and returns the natural logarithm.
math.log()方法是math模块的库方法,用于将给定数字的自然对数以e为底(默认情况下)。 它接受数字和一个底数(可选),并返回自然对数。
Note: If we provide anything else except a number, the method returns a TypeError – "TypeError: a float is required".
注意:如果我们提供除数字以外的任何其他内容,该方法将返回TypeError – “ TypeError:需要浮点数” 。
Syntax of math.log() method:
math.log()方法的语法:
math.log(x [, base])
Parameter(s):
参数:
x – is the number whose logarithm to be calculated.
x –是要计算其对数的数字。
base – is an optional parameter, it is used to defined any specific base for the logarithm.
base –是一个可选参数,用于定义对数的任何特定底数。
Return value: float – it returns a float value that is the natural or base specific logarithm of the number x.
返回值: float-返回一个浮点值,该值是数字x的自然或底数对数。
Example:
例:
Input:
x = 21
# function call
print(math.log(x))
Output:
3.044522437723423
Python代码演示math.log()方法的示例 (Python code to demonstrate example of math.log() method)
# python code to demonstrate example of
# math.log() method
# importing math module
import math
# log() with 1 parameter
x = 21
print("Natural logarithm of ", x, " is = ", math.log(x))
# log() with 2 parameters
x = 21
base = 5
print("logarithm of ", x, " with base ", base, " is = ", math.log(x, base))
Output
输出量
Natural logarithm of 21 is = 3.044522437723423
logarithm of 21 with base 5 is = 1.8916681496081529
翻译自: https://www.includehelp.com/python/math-log-method-with-example.aspx
python独立log示例