Python set len method

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


Python set len Example

The set len function helps you to find the set length or find 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 find its length using this set len function.

TIP: Please refer to Sets in Python.

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

# Python Set length
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))
Python set Len method 1