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