Key error '0' with dict format

后端 未结 1 1201

I\'m still a beginner in Python, and I wanted to know why this :

    dict = {}
    dict[0] = \'123\'
    a = 0
    if dict[\"{}\".format(a)][\"{}\".format(a)] ==         


        
相关标签:
1条回答
  • 2021-01-22 06:35

    You're trying to compare the key 0 with "0". They are different. One is an integer and another is a string.

    0 讨论(0)
提交回复
热议问题