+ 1
Python Dictionary output
Why the output is like this??? print({True: "yes", 1: "no", 1.0: "maybe"}) Output is: {True: "maybe"}
2 ответов
+ 8
Not sure whether this is the correct answer but looking at this code I can conclude something.
So there are 3 keys named TRUE, 1 and 1.0. And they are of three types (boolean, integer and double). Therefore python interpreter tries to parse all of these keys in to one value (making the key 1 and 1.0 to True). And therefore we get a lists which has 3 identical keys.
{True: "yes",True:"no",True:"maybe"}
By default we cannot have multiple keys with the same name in dictionaries. Therefore python overrides the value to the last assigned value ("maybe" in this case).
So finally we get this as the result
{True:"maybe"}
+ 1
Thank you my friend. Great help.