"Hello, world!" is not a problem with Python output, but if you output Chinese characters "Hello, World" you may encounter Chinese coding problem.
If no encoding is specified in the Python file, an error occurs during execution:
#!/usr/bin/python
"Hello, the World";
Run results
The default encoding format in Python is the ASCII format, which fails to print correctly when the encoding format is not modified, so the error occurs when reading Chinese.
The workaround is to add #-*-coding:utf-8-*- or #coding =utf-8 at the beginning of the file.
#!/usr/bin/python
#-*-Coding:utf-8-*-
"Hello, the World";
Run the result as
So if you are in the process of learning that the code contains Chinese, you need to specify the encoding in the header.
Note: python3.x source files use utf-8 encoding by default, so you can parse Chinese normally without specifying UTF-8 encoding.
Note: If you use the editor and you need to set the PY file storage format to UTF-8, you will receive an error message similar to the following:
SyntaxError:(Unicode error)'UTF-8' codec can'byte0xc4 In 0:byte
Pycharm Setup Steps:
- Go to file > Settingsand search for encodingin the input box.
- Locate Editor > File encodings, and set the IDE Encoding and Project Encoding to Utf-8.
Python Coding issues