Python math.pow()วิธี การ
ตัวอย่าง
หาค่า 9 ยกกำลัง 3:
# Import math Library
import math
#Return the value of 9 raised
to the power of 3
print(math.pow(9, 3))
ความหมายและการใช้งาน
วิธี การmath.pow()
คืนค่าของ x ยกกำลัง y
ถ้า x เป็นค่าลบ และ y ไม่ใช่จำนวนเต็ม จะส่งกลับ ValueError
เมธอดนี้แปลงอาร์กิวเมนต์ทั้งสองเป็นทศนิยม
เคล็ดลับ:หากเราใช้math.pow(1.0,x)
or math.pow(x,0.0)
มันจะคืนค่า 1.0 เสมอ
ไวยากรณ์
math.pow(x, y)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
x | Required. A number which represents the base |
y | Required. A number which represents the exponent |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ค่า ที่float แทนค่าของ x ยกกำลัง y (x y ) |
---|