Why is the output of this code "false".i thought it would be "apples" rather | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is the output of this code "false".i thought it would be "apples" rather

pairs = {1: "apple", "orange": [2, 3, 4], True: False, None: "True", } print(pairs.get(1))

20th Feb 2020, 5:17 PM
Beautiful Mind
Beautiful Mind - avatar
6 Answers
+ 2
True is automatically converted to 1. So the value mapped to 1 literally is False as True: False But, True = 1 => 1: False So .get(1) gives False
20th Feb 2020, 5:44 PM
XXX
XXX - avatar
+ 1
In programming True = 1 and False = 0. It probably saw 1 as True
20th Feb 2020, 5:31 PM
Jax
Jax - avatar
+ 1
Thanks guys
20th Feb 2020, 5:49 PM
Beautiful Mind
Beautiful Mind - avatar
0
So in that case..it was supposed to print "true" right?..but it printed "false"
20th Feb 2020, 5:32 PM
Beautiful Mind
Beautiful Mind - avatar
0
Oh
20th Feb 2020, 5:49 PM
Beautiful Mind
Beautiful Mind - avatar
0
Okay..that makes sense
20th Feb 2020, 5:49 PM
Beautiful Mind
Beautiful Mind - avatar