小编Isa*_*lor的帖子

在Python字典中使用变量作为键名

这感到多余:

name = 'Isaiah'
myInfo = {
  'name': name
}
Run Code Online (Sandbox Code Playgroud)

是否有一种较短的惯用方式来执行此操作,例如在JavaScript中:

myInfo = { name }
Run Code Online (Sandbox Code Playgroud)

编辑:从改变变量名dictmyInfo,因为dict是一个关键词。

python dictionary python-2.7

3
推荐指数
1
解决办法
4442
查看次数

标签 统计

dictionary ×1

python ×1

python-2.7 ×1