The 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 this Python len set function, and the basic syntax behind this is:
len(set_Name)
Python set len Example
The len function helps you find the set length or the total number of items in a given one. First, we declared an empty set and found its length. Next, we declared a numeric set and find its length using this len function.
TIP: Please refer to Sets in Python.
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))
