Can anyone please explain why set is behaving like this with boolean in it?

Viewed 93

set

Please explain the behavior of the set in the image. I know that set is unordered but where are the other elements from the set a & b ?

1 Answers

True and 1 are the same:

>>> True == 1
True
>>> 

Since sets can't have duplicate values, it only takes the one that appears first.

You can see that if you convert True to int:

>>> int(True)
1
>>>

The output is 1.

Related