36. Problem to check if two sets are equal

In this Python set program, we will check if two sets are equal or not 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 two sets are equal:

Steps to solve the program

1. Create two sets using {}.
2. Add some elements in the set.
3. Use an if-else statemnet with “==” operator to check if two sets are equal or not.
4. Print the respective output

				
					a = {1, 2, 4, 5, 7, 8, 9}
b = {2,3,4}
print("Original set1: ",a)
print("Original set2: ",b)
if a == b:
    print("Both sets are equal")
else:
    print("Both sets are not equal")
				
			

Output :

				
					Original set1:  {1, 2, 4, 5, 7, 8, 9}
Original set2:  {2, 3, 4}
Both sets are not equal
				
			

Related Articles

check if a set is empty.

check if a set is a frozen set.

Leave a Comment