Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

SymPy | Subset.cardinality() in Python

  • Last Updated : 26 Aug, 2019

Subset.cardinality() : cardinality() is a sympy Python library function that returns the number of all possible subsets.

Syntax :
sympy.combinatorics.subset.Subset.cardinality()

Return :
number of all possible subsets

Code #1 : cardinality() Example




# Python code explaining
# SymPy.Subset.cardinality()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
  
# Using from 
# sympy.combinatorics.subset.Subsets.cardinality()
  
# Creating Subset
a = Subset(['c', 'd'], ['geek', 'for', 'c', 'd'])
  
# cardinality value
print ("Subset a cardinality : ", a.cardinality)

Output :

Subset a cardinality : 16

Code #2 : cardinality() Example




# Python code explaining
# SymPy.Subset.cardinality()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
  
# Using from 
# sympy.combinatorics.subset.Subsets.cardinality()
  
# Creating Subset
a = Subset(['c', 'd'], ['23', 'c', 'd'])
  
  
# cardinality value
print ("Subset a cardinality : ", a.cardinality)

Output :

Subset a cardinality : 8


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!