Python math.factorial() Method
ตัวอย่าง
หาตัวประกอบของตัวเลข:
#Import math Library
import math
#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
ความหมายและการใช้งาน
math.factorial()
เมธอดจะคืนค่าแฟกทอเรียลของตัวเลข
หมายเหตุ:วิธีนี้ยอมรับเฉพาะจำนวนเต็มบวกเท่านั้น
แฟกทอเรียลของตัวเลขคือผลรวมของการคูณของจำนวนเต็มทั้งหมด จากจำนวนที่เราระบุลงไปที่ 1 ตัวอย่างเช่น แฟกทอเรียลของ 6 จะเท่ากับ 6 x 5 x 4 x 3 x 2 x 1 = 720
ไวยากรณ์
math.factorial(x)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
x | Required. A positive integer. If the number is negative, or not an integer, it returns a ValueError. If the value is not a number, it returns a TypeError |
รายละเอียดทางเทคนิค
คืนมูลค่า: | int ค่าบวก |
---|---|
เวอร์ชันหลาม: | 2.6 |