Python math.pow() 方法
math.pow() 方法是 math 模塊的一個庫方法,它用於計算一個基數的給定冪,它接受兩個數字並返回浮點數中第一個數字的第二個數字的冪。
math.pow() 方法的語法:
math.pow(a, b)
參數: a, b
– 需要計算其冪的數字(這裏,a
是基礎和b
是計算結果的能力a
的力量b
)。
返回值: float
– 它返回一個浮點值,它是a
的力量b
。
例:
Input: a = 2 b = 3 # function call print(math.pow(a, b)) Output: 8.0
用於演示 math.pow() 方法示例的 Python 代碼
# python code to demonstrate example of
# math.pow() method
# importing math module
import math
# numbers
a = 2
b = 3
# calculate a to the power of b
print(a, " to the power of ", b, " is = ", math.pow(a,b))
# numbers
a = 2.2
b = 3.0
# calculate a to the power of b
print(a, " to the power of ", b, " is = ", math.pow(a,b))
# numbers
a = 2
b = 0
# calculate a to the power of b
print(a, " to the power of ", b, " is = ", math.pow(a,b))
# numbers
a = 0
b = 3
# calculate a to the power of b
print(a, " to the power of ", b, " is = ", math.pow(a,b))
輸出
2 to the power of 3 is = 8.0 2.2 to the power of 3.0 is = 10.648000000000003 2 to the power of 0 is = 1.0 0 to the power of 3 is = 0.0
相關用法
- Python math.prod()用法及代碼示例
- Python math.perm()用法及代碼示例
- Python math.cos()用法及代碼示例
- Python math.cosh()用法及代碼示例
- Python math.acosh()用法及代碼示例
- Python math.fmod()用法及代碼示例
- Python math.fsum()用法及代碼示例
- Python math.remainder()用法及代碼示例
- Python math.asinh()用法及代碼示例
- Python math.atanh()用法及代碼示例
- Python math.fabs()用法及代碼示例
- Python math.log1p()用法及代碼示例
- Python math.gcd()用法及代碼示例
- Python math.frexp()用法及代碼示例
- Python math.isqrt()用法及代碼示例
- Python math.ldexp()用法及代碼示例
- Python math.acos()用法及代碼示例
- Python math.sin()用法及代碼示例
- Python math.sqrt()用法及代碼示例
- Python math.asin()用法及代碼示例
注:本文由純淨天空篩選整理自 math.pow() method with example in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。