I. Interpreter declaration
1. How to declare
Linux
#!/usr/bin/python
Windowns
#!c:/python27/python.exe
Put it on the first line
2. Role
Tell the computer to use the/usr/bin Program (tool) Python, the interpreter, to interpret/run the Python script.
Windows likewise.
Second, the code statement
1. How to declare
The declaration before the comment "#", the declaration of the first line of the file or the second line (the first line is the interpreter declaration, it is forced to write in the second line).
Take Utf-8 as an example, the following three kinds are legal
A. # encoding= Utf-8
B. #-*-Coding:utf-8-*-
C. #vim: Set fileencoding = Utf-8
Can tell the computer, I this file to use Utf-8 encoding.
2. Example explanation
A, the equals statement,
B, the colon declaration, "-*-" This thing is Emacs's editing habits, the actual no egg use
C,vim Declaration, the first two of the files are written
3. Identification method
The available code is declared in more ways than above, and the root cause is that the regular expression is used when Python recognizes it.
coding[:=]\s* ([-\w.] +)
4. Other
Python2, not declared, default ASCII code encoding
Python3, not declared, default Unicode encoding
Beginning of Python--a detailed document statement