def foo(**args):
for k, v in args.items():
print type(k), type(v)
for k, v in args.items():
k = v
print k
print type(k)
foo(a = 10)
foo(**{'a':10})
<type 'str'> <type 'int'>
10
<type 'int'>
<type 'str'> <type 'int'>
10
<type 'int'>
所以我很困惑,我怎么能做到这一点的k是一个字符串,所以我不应该不能够给它分配?
我显然无法做到
In [35]: 'a' = 10
------------------------------------------------------------
File "<ipython console>", line 1
SyntaxError: can't assign to literal (<ipython console>, line 1)
你想做什么?简单赋值有什么问题:a = 10?这背后的目标是什么? – 2009-10-28 12:52:48