# 字典合并问题

利用 update 方法，合并后是修改原来的字典，而不是新建一个字典作为返回值，比如：

```python
>>> x = {'a':1, 'b': 2}
>>> y = {'b':10, 'c': 11}
>>> z = x.update(y)
>>> print z
None
>>> x
{'a': 1, 'b': 10, 'c': 11}
```

## 解决方法一

```python
z = dict(x.items() + y.items())
```

其中相同的键的值会被后一个字典的值覆盖

另外，如果是 Python3：

```python
>>> z = dict(list(x.items()) + list(y.items()))
```

## 解决方法二

手动复制一遍再 update

```python
z = x.copy()
z.update(y)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://l1nwatch.gitbook.io/interview_exercise/stackoverflow-about-python/zi-dian-he-bing-wen-ti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
