带有Python示例的math.log2()方法
Pythonmath.log2()方法
math.log2()方法是math模块的库方法,用于获取数字的以2为底的对数,它接受数字并返回给定数字的以2为底的对数。
该方法math.log2()给出了更准确的结果比所述日志(X,2)。
注意:如果我们提供除数字以外的任何其他内容,该方法将返回TypeError–“TypeError:需要浮点数”。
math.log2()方法的语法:
math.log2(x)
Parameter(s):x–是要计算其以2为底的对数的数字。
返回值:float-它返回一个浮点数,该浮点数是数字x的以2为底的对数。
示例
Input:
x = 21
#函数调用
print(math.log2(x))
Output:
4.392317422778761Python代码演示math.log2()方法的示例
#python代码演示示例
#math.log2()方法
#导入数学模块
import math
#以2为底的对数
x = 21
print("Base-2 logarithm of ", x, " is = ", math.log2(x))
x = 10.23
print("Base-2 logarithm of ", x, " is = ", math.log2(x))输出结果
Base-2 logarithm of 21 is = 4.392317422778761 Base-2 logarithm of 10.23 is = 3.354734239970604
热门推荐
10 祝福语简短闺蜜文案
11 毕业男生聚餐祝福语简短
12 城堡文案简短婚礼祝福语
13 新进单位敬酒祝福语简短
14 事业祝福语简短工作
15 老人掉牙祝福语简短语
16 庆祝朋友离职祝福语简短
17 对航母的祝福语简短
18 元宵贺卡祝福语结婚简短