Python First Knowledge

Source: Internet
Author: User


One, the Python code executes the process:

The code is loaded into memory
Compile in-memory code into byte code
Compile bytecode into machine code

Second, the Python script is written

You need to define the script execution program (similar to Shell) in the first line of the script
#/usr/bin/python
The above is also possible, but the steps considered can be performed on other Linux (compatibility), so the first line of the script is redefined as
!/usr/bin/env python


Third, the classification of the Code
Ascii (2^8 up to 256 possible, limited, cannot display Chinese)
Unicode (Universal Code)
Use a minimum of 2 bytes, 1 characters, 3 bytes.
For example, I have a number 65, ASCII code is actually only 8 bit 0b1000001, but
If you use Unicode, use 16 bits, which wastes disk space

UTF-8
Unicode processing, to have all the English, digital, special characters with 8 bits. Resolves a problem where Unicode wastes disk.
English: 8 Guests
Europe: 16 people
English: 24 Guests


Four, define the code of the program (2.7 need to comment, if the use of more than 3.0 version can not comment, because the python3.0 version of the default encoding used is Utf-8)
3.0 The following version needs to be added again line comments as follows
#-*-Coding:utf-8-*-


Five, notes
#表示注释, if there is more than one line, use the
"""
Abc
Cbd
"""


Six, class library, built-in libraries and custom

Built-in libraries: generally stored in the Python installation directory in the LIB, there are some Python programs.

Custom libraries: Write a python script yourself.


Python programs typically do not consist of 1 files, which are then divided between the main program and the secondary program. If the main program needs to refer to the secondary program, just import.

Method of Import:

File name of import python

If the main program is executed at this point, a. pyc file is generated.


The. PYc file is a bytecode file that is generated by a. py file to increase the speed of code execution, and if you want to use the Python program in the future, use the. pyc file directly and do not need to find the Py file again, or you will convert the source to
Byte code, and finally in the conversion to machine code. The presence of the PYc file can directly convert the bytecode to machine code.

Python First Knowledge

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.