0

I am just a beginner in Python. I was learning dictionaries and just came through its 'get()' method. I wrote the following code:

nums = {
    1: 'one',
    2: 'two',
    3: 'three',
    True: False,
    None: 'Null'
}
print(nums.get(1))
print(nums.get(2))
print(nums.get(3))

The output I got was:

False
two
three

Here's an actual image of the output: Screenshot of the code and the output

As you notice, in the first line of output, it says 'False' but it must be 'One' according to the input. I would like to know the reason behind this wierd behaviour.

I just got a recommendation to go to Using True/False as keys - how/why does this work? and see if I understand, but I was unable to understand and I don't think that the context of my question matches with that of the recommended one. Also I need a deep explanation of what's happening here?

0 Answers0