r/PythonLearning • u/clcodingupdates • Oct 31 '26
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
r/PythonLearning • u/clcodingupdates • Oct 31 '26
What will be the output of the following Python Code?
print(len({True, 1, 1.0, False, 0}))
5
u/RNG_HatesMe Oct 31 '26
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 Oct 31 '26 edited Oct 31 '26
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/AgitatedRip4670 Oct 31 '26
2
2
u/W31337 Nov 01 '26
These questions make me hate languages like this... 🤪
If this were JavaScript the answer could be pi
1
u/Fluffy_white_fox 22d ago
It's 2
1
u/Jazzlike_Platypus430 Nov 01 '26
In normal world it would be 5, in python I wouldn't be surprised if it's -3.5.
0
u/farm_do1 Nov 01 '26
my answer is 2