r/PythonLearning • • 16d ago

Python Quiz of the Day!

What will be the output of the following Python Code?

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

6 Upvotes

11 comments sorted by

5

u/RNG_HatesMe 16d 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/Responsible-Age9224 15d ago

Thanks for explaining

1

u/Sea-Ad7805 16d ago edited 16d 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.

2

u/clcodingupdates 16d ago

Better luck next time.

2

u/Sea-Ad7805 15d ago

Thanks, always good to learn, or be humbled by making a mistake that you probably should have avoided as Python educator. These tests still trick you sometimes, nice job.

2

u/W31337 15d ago

These questions make me hate languages like this... 🤪

If this were JavaScript the answer could be pi

1

u/Jazzlike_Platypus430 15d ago

In normal world it would be 5, in python I wouldn't be surprised if it's -3.5.

0

u/farm_do1 15d ago

my answer is 2