Friday, September 26, 2025
HomeLanguagesPython | sympy.nC() method

Python | sympy.nC() method

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

Syntax: nC(items, k)

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

Returns: Returns the number of combinations 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.nC() method 
combinations = nC(items, k)  
      
print("Combinations : {}".format(combinations))  


Output:

Value of k = 3 and the items are = abca
Combinations : 3

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.nC() method 
combinations = nC(items, k)  
      
print("Combinations : {}".format(combinations))  


Output:

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

Most Popular

Dominic
32321 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11856 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6799 POSTS0 COMMENTS
Ted Musemwa
7072 POSTS0 COMMENTS
Thapelo Manthata
6759 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS