Python: create dictionary using dict() with integer keys?

后端 未结 3 1992
深忆病人
深忆病人 2021-02-03 18:11

In Python, I see people creating dictionaries like this:

d = dict( one = 1, two = 2, three = 3 )

What if my keys are integers? When I try this:

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-03 18:31

    a = dict(one=1, two=2, three=3)
    

    Providing keyword arguments as in this example only works for keys that are valid Python identifiers. Otherwise, any valid keys can be used.

提交回复
热议问题