What is the output of the following Python code? print(len({1, True, 1.0}))
Correct answer A. 1
Explanation
A set keeps only one of any group of equal elements. In Python True == 1 and 1 == 1.0, and these values also have equal hashes, so the set treats all three as the same element and keeps only the first one inserted. The length is therefore 1, not 3.
Answer checked How we write and check questions
Discussion