Daftar Referensi Python
math.perm() menghitung jumlah cara memilih k item dari n item ketika urutan penting.
Sintaks
math.perm(n, k=None)
Parameter
| Parameter | Wajib? | Keterangan |
|---|---|---|
n |
Ya | Jumlah total item, integer nonnegatif |
k |
Tidak | Jumlah item yang dipilih; default seluruh n |
Nilai balik: integer permutasi.
Contoh
import math
print(math.perm(5, 2))
Output:
20
Contoh Lainnya
Semua item
import math
print(math.perm(5))
Output:
120
Memilih nol item
import math
print(math.perm(8, 0))
Output:
1
k lebih besar dari n
import math
print(math.perm(3, 5))
Output:
0
Kesalahan Umum
- Argumen non-integer menghasilkan
TypeError. - Nilai negatif menghasilkan
ValueError. - Gunakan
math.comb()jika urutan tidak penting.
Pelajari Lebih Lanjut
- Referensi: math.comb() · math.factorial() · Modul math
- Buku Belajar Python untuk Pemula: Bab 16
