Python-附加到字典中的列表

Joe*_*rdi 5 python dictionary

我一直在尝试使用不同的字典在字典中的列表末尾添加一个值。分配有点复杂,所以我将问题简化为这三行,但结果不断得到 None 。

finley = {'a':0, 'b':2, 'c':[41,51,61]}
crazy_sauce = {'d':3}
print finley['c'].append(crazy_sauce['d'])
Run Code Online (Sandbox Code Playgroud)

San*_*ade 5

你的代码很好,但print finley['c'].append(crazy_sauce['d'])没有打印,因为finley['c'].append(crazy_sauce['d'])没有返回。您在此处删除打印并print finley['c']在下一行添加

finley = {'a':0, 'b':2, 'c':[41,51,61]}
crazy_sauce = {'d':3}
finley['c'].append(crazy_sauce['d'])
print finley['c']
Run Code Online (Sandbox Code Playgroud)