Python set len

The Python set len is one of the set methods used to find the length of a set (total number of items). This section discusses how to use the set len function, and the basic syntax behind this is:

len(set_Name)

The len function helps you find the set length or the total number of items in a given set. First, we declared an empty set and found its length. Next, we declared a numeric set and found its length using the len function.

TIP: Please refer to the Python set article available on our Learn Python page to understand the creation of sets. Also, check the list of available Python set functions.

emptySet = {}
print("\nOld Set Items = ", emptySet)

print("Length of a Set = ", len(emptySet))
      
myIntSet = {15, 25, 35, 45, 55}
print("\nOld Set Items = ", myIntSet)

print("Length of a Set = ", len(myIntSet))
set Len Example