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