Python dictionary doesn't have all the keys assigned, or items

后端 未结 4 1309
刺人心
刺人心 2021-01-17 07:44

I created the following dictionary

exDict = {True: 0, False: 1, 1: \'a\', 2: \'b\'}

and when I print exDict.keys(), well, it g

4条回答
  •  孤城傲影
    2021-01-17 08:15

    Python take the 1 as True. And the Boolean type is a subtype of the integer type

    In [1]: a = {}
    
    In [2]: a[True] = 0
    
    In [3]: 1 in a.keys()
    Out[3]: True
    

提交回复
热议问题