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 = 3print("Value of k = {} and the items are = {}".format(k, items)) # Use sympy.nP() method permutations = nP(items, k) print("Permutation : {}".format(permutations)) |
chevron_right
filter_none
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 = 3print("Value of k = {} and the items are = {}".format(k, items)) # Use sympy.nP() method permutations = nP(items, k) print("Permutation : {}".format(permutations)) |
chevron_right
filter_none
Output:
Value of k = 3 and the items are = [2, 1, 3, 5, 4] Permutation : 60
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | next() method
- Python | set() method
- Python | sympy RGS method
- Python PIL | UnsahrpMask() method
- Python | sys.getswitchinterval() method
- Python | sys.setswitchinterval() method
- Python | os.symlink() method
- Python | os.link() method
- Python | os.mkfifo() method
- Python | hasattr() method
- Python | os.fsync() method
- Python | os.times() method
- Python PIL | Image.new() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



