我有这样Python字典返回无
dict_a = {}
dict_a["key1"] = [["1","2"]]
我想用一个字符串3
来连接这个字典里面的值[["1","2"]]
的字典。所以我做了这样的事情:
new_list = list(dict_a["key1"])
dict_a["key1"] = new_list.append("3")
当我打印的字典,关键key1
它给了我一个None
,而不是[ “1”, “2”], “3”]
print dict_a["key1"]
甘蔗有人解释为什么我得到了“无”?
append()不会返回一个列表,它会更新您要追加的列表。 – monkut 2013-03-04 11:45:25
可能重复[Python,这是一个错误,追加到一个元组中的列表导致无?](http://stackoverflow.com/questions/9617906/python-is-this-a-bug-append-to -a-list-within-a-tuple-results-in-none) – 2013-03-04 11:48:52
而[为什么python的list.append评估为false?](http://stackoverflow.com/q/1682567) – 2013-03-04 11:49:29