![]() |
'dict()' Has an Exception? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: 'dict()' Has an Exception? (/thread-38606.html) |
'dict()' Has an Exception? - htran3 - Nov-04-2022 Hey guys, please let me know if you have an answer to this (copy and paste into your IDE): x = { 0: "value 0", 1: "value 1", 2: "value 2", True: False } print(x.get(0)) print(x.get(1)) print(x.get(2)) # output will look like this: # value 0 # False # value 2For some reason, only x.get(1) returns "False," and any other number or character will return with its dict definition. Does anyone know why that is? Thanks! RE: 'dict()' Has an Exception? - buran - Nov-04-2022 x to check what your dict looks likex = {0:"value 0", 1:"value 1", 2:"value 2", True:False} print(x) TLTR: Key True is same as 1 thus last seen wins.Check https://peps.python.org/pep-0285/ Quote:The Quote:6. Should bool inherit from int? RE: 'dict()' Has an Exception? - htran3 - Nov-04-2022 Thank you so much! That makes a lot of sense now. |