4. Problem to find the length of a set

In the Python set program, we will find the length of a set and print it to see the total number of elements in that set with the help of the below-given steps.

What is set?
Sets are used to store multiple items in a single variable.
The set is one of 4 built-in data types in Python used to store collections of data.
It is an unordered collection data type that is iterable, mutable and has no duplicate elements.

Length of a set:

Steps to solve the program

1. Create a set using {}.
2. Add some elements to the set.
3. Find the length of set using the len() function.
4. Print the output.

				
					a = {1,2,3,5,6}
print("Original set: ",a)
print("Length of given set: ",len(a))
				
			

Output :

				
					Original set:  {1, 2, 3, 5, 6}
Length of given set:  5
				
			

remove an element from a set.

check if an element is present in a set.

Leave a Comment