Is there a difference between using a dict literal and a dict constructor?

10/14 04:09
阅读数 0

问题:

Using PyCharm, I noticed it offers to convert a dict literal :使用 PyCharm,我注意到它提供了转换dict 文字的功能

d = {
    'one': '1',
    'two': '2',
}

into a dict constructor :进入dict 构造函数

d = dict(one='1', two='2')

Do these different approaches differ in some significant way?这些不同的方法是否在某些重要方面有所不同?

(While writing this question I noticed that using dict() it seems impossible to specify a numeric key .. d = {1: 'one', 2: 'two'} is possible, but, obviously, dict(1='one' ...) is not. Anything else?) (在写这个问题时,我注意到使用dict()似乎不可能指定数字键 .. d = {1: 'one', 2: 'two'}是可能的,但是,显然, dict(1='one' ...)不是。还有别的吗?)


解决方案:

参考一: https://en.stackoom.com/question/Rjig
参考二: https://stackoom.com/question/Rjig
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部