How come I can add the boolean value False but not True in a set in Python? [duplicate]

Because in Python 1 == True (and hash(1) == hash(True)) and you have 1 in your set already.

Imagine this example:

example1 = {0, False, None}
example2 = {1, True}

print(example1)
print(example2)

Will output:

{0, None}
{1}

First set has 0 and None because 0 == False but 0 != None. With second set 1 == True so True isn’t added to the set.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)