Python set len method

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:


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))
Python set Len Example 1

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.