Beginning of Python--a detailed document statement

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.