Why does this code written true,maybe ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

Why does this code written true,maybe ?

Dict1={True:'Yes',1:'No',1.0:'Maybe'} Dict2={1:'No',1.0:'Maybe'} print(dict1) print(dict2)

1st Aug 2020, 11:53 PM
Nikki Singh
2 Answers
+ 5
Hi! I found this on Real Python: “First, a given key can appear in a dictionary only once. Duplicate keys are not allowed. A dictionary maps each key to a corresponding value, so it doesn’t make sense to map a particular key more than once. If you specify a key a second time during the initial creation of a dictionary, then the second occurrence will override the first.” Source (2020-08-02): https://realpython.com/lessons/restrictions-dictionary-keys-and-values/ Regards /Per B
2nd Aug 2020, 1:25 AM
Per Bratthammar
Per Bratthammar - avatar