+ 2

printing none value

pairs = {1: "apple", "orange": [2, 3, 4], True: False, None: "Key Not present", } print(pairs.get("orange")) print(pairs.get(7)) print(pairs.get(12345, "not in dictionary")) Output: [2, 3, 4] None not in dictionary In print(pairs.get(7)) it prints "None" , can we instead of printing "None", print the value of "None" i.e. "True"

26th Mar 2017, 1:25 PM
Vaibhav Singh
Vaibhav Singh - avatar
2 Antworten
+ 3
pairs = {1: "apple", "orange": [2, 3, 4], True: False, None :True } print(pairs.get("orange")) print(pairs.get(7,)) print(pairs.get(12345, "not in dictionary")) print(pairs.get(None)) Output: [2,3,4] None not in dictionary True this really made me understand
27th Mar 2017, 6:38 AM
Vaibhav Singh
Vaibhav Singh - avatar
+ 2
print(pairs.get(7, True)) Oh BTW, None evaluates to False (not True) when coerced into Boolean type.
27th Mar 2017, 5:19 AM
Álvaro