+ 1

Python

#I got this from trying some variations: test_dictionary01 = { 1: "apple", True: "pear", } print(test_dictionary01.get(1)) print(test_dictionary01.get(True)) test_dictionary02 = { 1: "apple", "True": "pear", } print(test_dictionary02.get(1)) print(test_dictionary02.get(True)) test_dictionary03 = { 1: "apple", "True": "pear", } print(test_dictionary03.get(1)) print(test_dictionary03.get("True")) #.how the output is misbehaving I am unable to understand 🙃

14th Jul 2018, 6:06 PM
Anand Agrawal
3 Answers
+ 1
True is a reserved word in Python. Don't use it for variables or keys. Only the last one is ok, because there it is a string. Otherwise True is the same as 1 That's also why in your second dict it only prints apple, since the string "True" is not called in any statement.
14th Jul 2018, 6:19 PM
Matthias
Matthias - avatar
+ 1
got it thanks bro 🙏 r u on discord as I wanted help for some screenshots of code if u have time..
14th Jul 2018, 6:26 PM
Anand Agrawal
0
I am on discord, yes, but only from time to time. I only use it on PC and don't know when I can login again đŸ˜¶
14th Jul 2018, 6:31 PM
Matthias
Matthias - avatar