在Python 3.x中,字符串默认支持Unicode,因此不需要在字符串前加`u`来表示Unicode字符串。如果你在Python 3.x中尝试使用`u`前缀,比如`str=u'汉字'`,你会得到一个语法错误,因为这是Python 2.x的语法。
```python
-*- coding: utf-8 -*- 指定文件编码为UTF-8
print('中文') 直接打印Unicode字符串
如果你在Python 2.x中处理Unicode字符串,你需要使用`u`前缀,并且确保文件编码设置为UTF-8,例如:
```python
-*- coding: utf-8 -*- 指定文件编码为UTF-8
str = u'汉字' 使用u前缀定义Unicode字符串
print(str) 打印Unicode字符串
请注意,如果你在Python 2.x中遇到`UnicodeDecodeError`,可能是因为`.py`文件保存的格式不是UTF-8编码。