Friday, September 5, 2025
HomeLanguagesPython | sympy.nP() method

Python | sympy.nP() method

With the help of sympy.nP() method, we can calculate the number of permutation of a given length in SymPy.

Syntax: nP(items, k)

Parameter:
items – An integer, a list or a string upon which permutation is to be calculated.
k – An integer specifying the length of the permutation.

Returns: Returns the number of permutation of a given length.

Example #1:




# import sympy 
from sympy import * 
  
items = "abca"
k = 3
print("Value of k = {} and the items are = {}".format(k, items))
   
# Use sympy.nP() method 
permutations = nP(items, k)  
      
print("Permutation : {}".format(permutations))  


Output:

Value of k = 3 and the items are = abca
Permutation : 12

Example #2:




# import sympy 
from sympy import * 
  
items = [2, 1, 3, 5, 4]
k = 3
print("Value of k = {} and the items are = {}".format(k, items))
   
# Use sympy.nP() method 
permutations = nP(items, k)  
      
print("Permutation : {}".format(permutations))  


Output:

Value of k = 3 and the items are = [2, 1, 3, 5, 4]
Permutation : 60
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS