> For the complete documentation index, see [llms.txt](https://m0uk4.gitbook.io/notebooks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://m0uk4.gitbook.io/notebooks/mouka/python/python-tricks/he-bing-liang-ge-zi-dian.md).

# 合并两个字典

&#x20;**Python 版本 > 3.5**

```python
>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 3, 'c': 4}

>>> z = {**x, **y}    # 一行代码合并两字典
>>> z
{'c': 4, 'a': 1, 'b': 3}
```

**Python 版本 2.x**

```python
>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 3, 'c': 4}

>>> z = dict(x, **y)
>>> z
{'a': 1, 'c': 4, 'b': 3}
```
