- 3
why python give this output ?
print({True:'yes', 1 : 'no', 1.0 : 'maybe'}) *********OUTPUT**************** {True : 'maybe'}
12 ответов
- 2
i added : dict have unique keys.
that is :
{1: "hellO" , 1 : "world" } -----converted into ------>>> {1:"world"}
________________________________________________________________
And True is == 1
therefore {1: "hello" , True: "world"} --------converted into -------> {1 : 'hello', 1 : "world"} (last one) ---------converted into-------> {1 : 'world'}
+ 6
because 1 and 1.0 are evaluated as True, so result is a dict with only one key with last value^^
+ 4
Angela all three values are set to same dict key (True), in order of apparence, so only last remain ;)
+ 4
JITEN.Py (active learner:) { 1: "hello", True: "world" } result to { 1: "world" }, not to { True: "world" }
first key, last value, in case of key not string that are evaluated as same values ^^
however, in both case you can access key by any key evalued to same value (that's 1, 1.0 or True)
+ 1
I’m not 😪
+ 1
now I got it. It takes always the last value, if there are several values for the same key
+ 1
JITEN.Py (active learner:) that's shame to mark its own answer as 'best', all the more after receiving correct explanation and by giving a not correct answer ^^
+ 1
JITEN
Just as future reference, please next time avoid writing code into the tags
https://code.sololearn.com/W3uiji9X28C1/?ref=app
0
Thanks for clarification
0
Yes
- 1
Got it :)
- 1
visph thx for correction