nicomp
nicomp

Reputation: 4657

Why can't I store True in a Set?

I have this code:

mySet = {1,"2",3.0,True}
print("Set: " , mySet)

The output is

Set:  {1, 3.0, '2'}

What happened to the 'True' ?

Upvotes: 2

Views: 129

Answers (1)

I'mahdi
I'mahdi

Reputation: 24059

Because set save unique value one time and 1 and True == 1 are same. For this reason, you see 1 one time.

>>> {1,True}
{1}

>>> {0,False}
{0}

>>> {'1',True}
{'1',True}

Upvotes: 5

Related Questions