Middle
What is the difference between == and is? What will print({1} == {1})?
sobes.tech AI
Answer from AI
In Python, the == operator checks for equality of object values, meaning it compares the contents.
The is operator checks whether two variables point to the same object in memory (object identity).
Example:
a = [1, 2]
b = [1, 2]
print(a == b) # True, because the lists contain the same elements
print(a is b) # False, because they are different objects
In your example print({1} == {1}), two sets each containing the number 1 are compared. Since sets with the same elements are equal, the output will be:
True