I don't konw why False as this case | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I don't konw why False as this case

hi i am not good english i have a question. i think result of next code is 'apple'. but result is False please answer why. pairs = { 1: "apple","orange": [2, 3, 4], True: False, None: "True",} print(pairs.get(1)) print(pairs[1])

19th Mar 2017, 11:11 PM
김우겸
김우겸 - avatar
3 Answers
+ 6
In python there no real boolean values True and False. So, 1 and True are totally same, and your litteral dict declaration override the value of '1' key by the value of 'True' key ^^ On the other hand, the string "1" is different of the integer '1', so you can make distinct keys with string and number...
20th Mar 2017, 7:22 AM
visph
visph - avatar
0
it is taking 1 as boolean true. so maybe typecasting it into an integer might help.
20th Mar 2017, 3:18 AM
Puspal Ghosh
Puspal Ghosh - avatar
0
think you! very much.^^
21st Mar 2017, 11:05 PM
김우겸
김우겸 - avatar