> For the complete documentation index, see [llms.txt](https://close.gitbook.io/yun-wei-bi-ji/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](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).

# 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)
```
