First, Content coding
It is clear that the ASCII code cannot represent all the words and symbols in the world, so it is necessary to create a new encoding that can represent all the characters and symbols, namely: Unicode
Unicode (Uniform Code, universal Code, single code) is a character encoding used on a computer. Unicode is created to address the limitations of the traditional character encoding scheme, which sets a uniform and unique binary encoding for each character in each language, which specifies that characters and symbols are represented by at least 16 bits (2 bytes), that is: 2 **16 = 65536,
Note: Here is a minimum of 2 bytes, possibly more
UTF-8, which is compression and optimization of Unicode encoding, does not use a minimum of 2 bytes, but instead classifies all characters and symbols: the contents of the ASCII code are saved with 1 bytes, the characters in Europe are saved in 2 bytes, and the characters in East Asia are saved in 3 bytes ...
Therefore, when the Python interpreter loads the code in the. py file, it encodes the content (the default ascill), if it is the following code:
Error: ASCII code cannot be expressed in Chinese
[email protected] ~]# cat hellow.py #!/usr/bin/env pythonprint "Hello World" print "Hello, worlds" [[email protected] ~]# python he llow.py file "hellow.py", line 4syntaxerror:non-ascii character ' \xe4 ' in File hellow.py on line 4, but no encoding dec lared; See http://www.python.org/peps/pep-0263.html for details
Correction: It should be shown to tell the Python interpreter what code to use to execute the source code, i.e.:
[[email protected] ~]# cat hellow.py #!/usr/bin/env python#-*-coding:utf-8-*-print "Hello World" print "Hello, worlds" [[Email P rotected] ~]# python hellow.py Hello worlds Hello World
Second, the note
When the line stares: # is annotated content
Multiline Comment: "" "Annotated Content" ""
three . Write and execute Python code flow
1, create xxx.py file PS: Do not have Chinese path, the file name is not Chinese
2. Write code
A. Add #!/usr/bin/env python and #-*-coding:utf-8-*-two lines at the beginning of the. py file
B. Write function code
#写功能代码的规则
3. Execute code
A. Open the terminal
Function key +r re-enter CMD press ENTER (Windows)
B. Path to Python code files
This article from "Mr.xiong ' s operation and maintenance log" blog, reproduced please contact the author!
Python Coding and code comments