# Python中反斜杠u类型（uXXXX）字符串转换为Unicode字符串

### 1.问题

遇到类似于str = "\u65b0\u589e\u4f1a\u5458" 类型的字符串，想将这种字符串转换成Unicode类型的字符串，即中文字符串，该怎么做？

### 2.解决方法

通过Python中的encode函数先将上述字符串str编码成utf-8类型的字符串，再用decode函数将字符串解码就行了，具体操作代码如下：

```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

str = "\\u65b0\\u589e\\u4f1a\\u5458"
decoded_u = str.encode('utf-8').decode('unicode_escape')
print('\\u65b0\\u589e\\u4f1a\\u5458:', decoded_u)
```


---

# 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://close.gitbook.io/yun-wei-bi-ji/python/python-xiao-ji-qiao/python-zhong-fan-xie-gangulei-xing-uxxxx-zi-fu-chuan-zhuan-huan-wei-unicode-zi-fu-chuan.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.
