Skip to main content

Discrete Math with SageMath: Learn math with open-source software

Section 2.2 Cardinality

To find the cardinality of a set, we use the cardinality() function.
Alternatively, we can use the Python len() function. Instead of returning a Sage Integer, the len() function returns a Python int.
In many cases, using Sage classes and functions will provide more functionality. In the following example, cardinality() gives us a valid output while len() does not.