I. Knowledge RESERVE
cpu--Control and operation
Memory--Temporarily store data required by the CPU
Hard drive--permanently save data
2. Principles of the text editor principle of storage
1. Start the text editor
2, enter the content on the editor---at this time the input is still in memory
3, save to hard drive
Conclusion: When writing the PY program, there is no limitation of grammar, the result of editing and the writing
An ordinary text file does not make any difference, only the PY program is given to the Python interpreter to explain
And the third stage of execution makes sense.
How the 3.python interpreter executes the Python program
Python3 test.py
First stage: Start the Python interpreter first software
Phase II: Read the contents of the test.py file into memory
Phase III: Interpreting execution, recognizing grammar
4. Text Editor Reading principle
1. The editor sends requests to the operating system
2. The operating system takes data out of the hard disk and loads it in memory
3. The application prints the content through the operating system
Two. What is character encoding
Character encoding is the process of translating human languages into binary systems that can be understood by computers.
The principle of the process of translation-character encoding table (the relationship between characters and binary number one by one)
The development of character encoding:
ASCII code: English characters only, one English character takes 1 bytes
GBK: Chinese Custom coded table, 2 bytes in Chinese, 1 bytes in English
Unicode: (Fixed encoding in memory)--2 bytes for one character
Upgraded version of Uft-8:unicode, resolves the issue of Unicode wasting memory space
1 bytes represents an English character, and 3 bytes represents a Chinese character
Three. Ensure that the core is not garbled:
What encoding the file has to be read with
Emphasis: We can only control the existence of the code on the hard drive
Python3 Interpreter: Default UTF--8 encoding
Python2 Interpreter: Default ASCII encoding
The role of the file header:
#coding: Utf-8 tells the interpreter to use the character encoding I specified
Four. What happens in the third stage of executing a python program
The Python syntax is recognized, and the defined string type involves the concept of character encoding
Example:
x= ' on ' #x =str (' on ')
Python2:
There are two forms of string
x= ' on ' #python2的str类型会按照文件头指定的编码来存 '
Python3:
STR: default is saved as Unicode
Five. Convert between Unicode and other encodings
Unicode---encoded encode--->GBK
GBK-------> Decoding decode--->unicode
Python path--day6--character encoding