Python program to find Length of a set

#Create a set
setn = {5, 10, 3, 15, 2, 20}
print("Original set elements:")
print(setn)
print(type(setn))
print("\nLength of the said set:")
print(len(setn))
setn = {5, 5, 5, 5, 5, 5}
print("Original set elements:")
print(setn)
print(type(setn))
print("\nLength of the said set:")
print(len(setn))
setn = {5, 5, 5, 5, 5, 5, 7}
print("Original set elements:")
print(setn)
print(type(setn))
print("\nLength of the said set:")
print(len(setn))

OUTPUT:

Original set elements:
{2, 3, 5, 10, 15, 20}
<class 'set'>
Length of the said set:
6
Original set elements:
{5}
<class 'set'>
Length of the said set:
1
Original set elements:
{5, 7}
<class 'set'>
Length of the said set:
2

Leave a Comment