【发布时间】:2011-03-16 01:52:04
【问题描述】:
这是我的代码:
a={}
a['b']=0
print a['b']
这是我的另一个代码(这是错误的):
a={}
a.b=0
print a.b
还有其他方法可以设置与 python dict 中的键关联的值吗?
【问题讨论】:
-
我想用get之类的方法,a.get('b',0),所以a.set('b',0)
-
您在阅读本文时遇到问题吗? docs.python.org/library/stdtypes.html#mapping-types-dict
标签: python dictionary