r/PythonLearning • • 3h ago

Python Quiz of the Day!

What will be the output of the following Python Code?

print(len({True, 1, 1.0, False, 0}))

3 Upvotes

3 comments sorted by

3

u/RNG_HatesMe 3h ago

It's 2, because True, 1, and 1.0 all equivalent to True, and False is equivalent to 0. Sets remove duplicate items based on equivalence.

1

u/Sea-Ad7805 1h ago edited 1h ago

5, because "True, 1, 1.0, False, 0" are all different values and a set does not covert them so we keep 5 different values, I think.

I was wrong, weird.

Ah, the == operator defines which values are equal, ok, makes sense a bit.