python独立log示例
Python math.log10()方法 (Python math.log10() method)
math.log10() method is a library method of math module, it is used to get the base-2 logarithm of a number, it accepts a number and returns base-10 logarithm of the given number.
math.log10()方法是math模块的库方法,用于获取数字的以2为底的对数,它接受数字并返回给定数字的以10为底的对数。
The method math.log10() gives more accurate result than the log(x, 10).
与log(x,10)相比, math.log10()方法给出的结果更准确。
Note: If we provide anything else except a number, the method returns a TypeError – "TypeError: a float is required".
注意:如果我们提供除数字以外的任何其他内容,该方法将返回TypeError – “ TypeError:需要浮点数” 。
Syntax of math.log10() method:
math.log10()方法的语法:
math.log10(x)
Parameter(s):x – is the number whose base-10 logarithm to be calculated.
参数: x –是要计算其以10为底的对数的数字。
Return value: float – it returns a float value that is the base-10 logarithm of the number x.
返回值: float-它返回一个浮点数,该浮点数是数字x的以10为底的对数。
Example:
例:
Input:
x = 21
# function call
print(math.log10(x))
Output:
1.3222192947339193
Python代码演示math.log10()方法的示例 (Python code to demonstrate example of math.log10() method)
# python code to demonstrate example of
# math.log10() method
# importing math module
import math
# Base-10 logarithm
x = 21
print("Base-10 logarithm of ", x, " is = ", math.log10(x))
x = 10.23
print("Base-10 logarithm of ", x, " is = ", math.log10(x))
Output
输出量
Base-10 logarithm of 21 is = 1.3222192947339193
Base-10 logarithm of 10.23 is = 1.0098756337121602
翻译自: https://www.includehelp.com/python/math-log10-method-with-example.aspx
python独立log示例