python独立log示例_带有Python示例的math.log()方法
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 callprint(math.log(x))Output:3.044522437723423Python代碼演示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示例
總結
以上是生活随笔為你收集整理的python独立log示例_带有Python示例的math.log()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 8086 寻址方式_8086微处理器的不
- 下一篇: 为什么在Python中使用string.