It is normal to run under IDLE. The poster didn't tell you how you run it?
The output characters will be converted into the terminal encoding.
The default cmd under windows is cp936. So when you run it directly, python will try to convert this character into gbk encoding, and this will happen after the conversion fails.
One solution is to execute your code in IDLE.
Method 2, first execute chcp 65001 in cmd to change the default encoding of cmd to unicode, and then execute python http://imysqldba.blog.51cto.com/1222376/706672
If you remove # coding=utf-8 in the code, the following exception will be thrown: # coding=utf-8去掉,抛如下异常:
SyntaxError: Non-ASCII character '\xc2' in file D:\web\file_test.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
然后我又写成这样:
# coding=utf-8
b = '\xa9'
print b
报错了:
Decode error - output not utf-8
(这个错是Sublime的问题,在命令行下未报错,也什么都没输出)
虽然我用的是2.7
rrreee
Then I wrote like this:
rrreee
🎜Error reported:🎜
rrreee
🎜Although I am using 2.7 and the exception is different from the subject, you can refer to it. 🎜Coding issues have always been one of the biggest headaches for programmers...🎜
python3
It is normal to run under IDLE. The poster didn't tell you how you run it?
The output characters will be converted into the terminal encoding.
The default cmd under windows is cp936.
So when you run it directly, python will try to convert this character into gbk encoding, and this will happen after the conversion fails.
One solution is to execute your code in IDLE.
Method 2, first execute chcp 65001 in cmd to change the default encoding of cmd to unicode, and then execute python
http://imysqldba.blog.51cto.com/1222376/706672
Output result:

If you remove
# coding=utf-8
in the code, the following exception will be thrown:# coding=utf-8
去掉,抛如下异常:然后我又写成这样:
报错了:
虽然我用的是
rrreee 🎜Error reported:🎜 rrreee 🎜Although I am using2.7
rrreeeThen I wrote like this:
2.7
and the exception is different from the subject, you can refer to it. 🎜Coding issues have always been one of the biggest headaches for programmers...🎜Maybe it’s a problem with the terminal. I use IDLE that comes with python 2.7.6, and no error is reported, but a box is output
This character is regarded as a gbk character. Are you sure the copyright symbol is written like this?
Try setting the environment variable language
I specially installed 3.5.1 and tried it
There seems to be no problem here