Comparing Sets in Python
To compare whether all elements of one set are the same as the second, the operator ==
is used. If the sets are equal to each other, the Boolean value True
is returned, otherwise - False
.
Let's compare two sets:
st1 = {1, 2, 3, 4}
st2 = {2, 1, 3, 4}
print(st1 == st2) # True
Now let's compare the following sets:
st1 = {8, 6, 4, 2}
st2 = {5, 8, 2, 4}
print(st1 == st2) # False
The following code is given:
st1 = {'a', 'f', 'e', 'b'}
st2 = {'f', 'a', 'b', 'e'}
print(st1 == st2)
Tell me what will be output to the console.
The following code is given:
st1 = {'1', '4', '2', '3'}
st2 = {'2', '3', '4', 1}
print(st1 == st2)
Tell me what will be output to the console.