无法在Python中合并两个字典。

2024-05-07 23:52:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个函数,它返回两个字典。 在第三个函数中,我尝试使用update合并这些字典,但是在打印时得到了None的结果。 有人能解释一下我的错误吗?在

def first():
    dict1 = {
        one : [1, 2, 3]
    }
    return dict1

def second():
    dict2 = {
        two : [3, 4, 5]
    }
    return dict2

def third():
    return first().update(second)


print(third())
>>> None

我也试过这样做:

^{pr2}$

顺便说一下,这种方法在Python 3.4中不起作用:

^{3}$

Tags: 函数nonereturn字典def错误updateone