Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

set

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 ?

like image 283
Suraj Tripathi Avatar asked Aug 17 '21 07:08

Suraj Tripathi


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.

like image 86
U12-Forward Avatar answered Oct 20 '22 21:10

U12-Forward