5. Problem to check if an element is in a set

In this python set program, we will check if an element is in a set and if yes then we will print True, else print False 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.

Check if an element is in a set:

Steps to solve the program

1. Create a set using {}.
2. Add some elements in the set.
3. Use an if-else statement to check whether 5 is in the set or not.
4. Print the respective output.

				
					a = {1,2,3,5,6}
print("Original set: ",a)
if 5 in a:
    print("True")
else:
    print("False")
				
			

Output :

				
					Original set:  {1, 2, 3, 5, 6}
True
				
			

Find the length of a set.

find the union of two sets.

Leave a Comment