+ 6

[Solved] 1, 1.0, True

In this following code, I expect to get the output: "apple" but I don't know why python gives me the output "False". Can anyone tell me why? pairs = {1: "apple", "orange": [2, 3, 4], True: False, None: True, } print(pairs.get(1)) "Thank you guys for your answers, now I got it and understood dictionaries better." 🌹❤ Case Solved. ✅

28th Feb 2022, 4:48 PM
Siavash Kardar Tehran
Siavash Kardar Tehran - avatar
4 Respostas
+ 12
True 1.0 1 have the same hashvalue. Therefore pairs[1]=pairs[1.0]=pairs[True]=False
28th Feb 2022, 4:51 PM
Oma Falk
Oma Falk - avatar
+ 5
Thank you. 🌹
28th Feb 2022, 5:02 PM
Siavash Kardar Tehran
Siavash Kardar Tehran - avatar
+ 3
Please print out pairs to see for yourself.
28th Feb 2022, 4:53 PM
Slick
Slick - avatar