Explain | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Explain

can anyone explain me this? print({True:"yes",1:"no",1.0:"Maybe"}) output: {True: 'Maybe'}

30th Oct 2019, 11:42 AM
JeyDeeSk
2 Answers
+ 5
For a dictionary, True, 1 and 1.0 are actually the same thing. So key 1 is overwritten two times and gets stuck at value 'Maybe'. The dict has only one item.
30th Oct 2019, 1:28 PM
HonFu
HonFu - avatar
- 1
maybe
1st Nov 2019, 10:22 AM
Krishna Chaudhary
Krishna Chaudhary - avatar