The spring breeze is warm, slightly has a little indisposition. If the heart is safe, everything is fine. It's a beautiful thing to be able to fight with loved ones.
---aaron.shen
May 15 Sunny
The main contents of today's class are as follows:
1, character encoding:
Python3 default is UTF8
Extract:
Character encoding
The Python interpreter encodes the content when it loads the. py file (default Ascill)
ASCII (American Standard Code for Information interchange, United States Standards Information Interchange Code) is a set of computer coding systems based on the Latin alphabet, mainly used to display modern English and other Western European languages, It can only be represented by a maximum of 8 bits (one byte), that is: 2**8=256-1, so the ASCII code can represent up to 255 symbols.
So a new code that can represent all the characters and symbols is introduced, namely: Unicode specifies that all characters and symbols are represented by at least 16 bits (2 bytes), i.e.: 2**8=65536
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 with 2 bytes, and the characters in East Asia are saved in 3 bytes ...
So when the Python interpreter loads the code in the. py file, the content is encoded (default ASCII).
2, about comments:
Mainly divided into # and ' ' or ' ""
The use of the # number, the use of multiple lines of "or" "
3, module:
Reference Method Import Os,sys
Import OS
Os.system ("df-th") #调用系统命令
4, abstract PYc Detailed:
What the hell is a. pyc?
1. interpreted language and compiled language
Computers are not able to recognize high-level languages, so when we run a high-level language program, we need a "translator" to engage in the process of translating high-level languages into machine languages that computers can read. This process is divided into two categories, the first of which is compilation, and the second is interpretation.
A compiled language before a program executes, the program executes a compilation process through the compiler, transforming the program into machine language. The runtime does not need to be translated and executes directly. The most typical example is the C language.
The explanatory language does not have this process of compiling, but rather, when the program is running, it interprets the program line by row, then runs directly, and the most typical example is Ruby.
Through the above example, we can summarize the advantages and disadvantages of the explanatory language and the compiled language, because the compiler language before the program has already made a "translation" of the program, so at run time there is less "translation" process, so the efficiency is higher. But we also can't generalize, some interpretive languages can also be optimized by the interpreter to optimize the whole program when translating the program, thus more efficiently than the compiled language.
In addition, with the rise of virtual machine-based languages such as Java, we cannot simply divide the language into two types-----explanatory and compiled.
In Java, for example, Java is first compiled into a bytecode file by a compiler and then interpreted as a machine file by the interpreter at run time. So we say that Java is a language that is compiled and interpreted first.
2. Brief description of Python's running process
Before we say this question, let's start with two concepts, pycodeobject and PYC files.
The PYC we see on the hard drive naturally doesn't have to say much, and pycodeobject is actually the result of a Python compiler actually compiling it. Let's just get to the bottom of it and keep looking down.
When the Python program runs, the result of the compilation is saved in the Pycodeobject in memory, and when the Python program finishes running, the Python interpreter writes Pycodeobject back to the PYc file.
When the Python program runs for the second time, the program will first look for the PYc file on the hard disk, and if it is found, load it directly or repeat the process. ( If. Py is changed, compare. PY and. PYc the latest modified time. ). We should do this to locate the Pycodeobject and PYc files, and we say that the PYc file is actually a persistent way to save the pycodeobject.
5, Data type:
Summary Category:
1. Digital
2 is an example of an integer.
Long integers are just larger integers.
3.23 and 52.3E-4 are examples of floating-point numbers. The e tag represents a power of 10. Here, 52.3E-4 means 52.3 * 10-4.
( -5+4j) and (2.3-4.6j) are examples of complex numbers.
int (integral type)
On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807long (Long integer)
Unlike the C language, Python's long integers do not refer to the positioning width, that is, Python does not limit the size of long integer values, but in fact, because of limited machine memory, we use a long integer value can not be infinite.
Note that, since Python2.2, Python automatically converts integer data to long integers if an integer overflows, so it does not cause any serious consequences if you do not add the letter L after long integer data.
Float (float type)
A floating-point number is used to process real numbers, which are numbers with decimals. Similar to the double type in C, accounting for 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one represents the symbol.
Complex (plural)
The complex number consists of real and imaginary parts, the general form is X+yj, where x is the real part of the complex, and Y is the imaginary part of the complex, where x and y are real numbers. Note: A small number pool exists in Python:-5 ~ 257 2, Boolean true or False 1 or 0 6, String: The evil + number, will occupy too much memory space. Detailed methods can be described in the previous string summary. String Common functions:
- Remove Blank-----Strip
- Split------Split
- Length--------Len
- Index-------[]
- Slice-------[:]
7, List:
[] Represents the list
Summary:
Create a list
List corresponding numbers are subscript,List.sort 3.0 numbers and characters cannot be sorted together ,del delete data in memory, global use
Name_list = [' Alex ', ' Seven ', ' Eric '] or name_list = List ([' Alex ', ' Seven ', ' Eric '])
Slice
#切片可以之后再切片 >>> name=[11,22,33,44,55,66]>>> name[:5][2:4][0]33
For additions and deletions to search:
1Group = ['Shen Colung','Ma Daqiang','Liu Lidong','Liu Meide','Wang Zhixua','Yu Xiaoyan','Rothen']2 Print(group)3Group.insert (5,'qinling')4Group.insert (6,'Qin Two')5 Print(group)6 #print (Group[2:8])7Group.remove (group[7])8 Print(group)9 Ten delGroup[5:7] One Print(group) AGroup[0] ='Shen Colung-group leader' - Print(group) -Group = Group[::2] the Print(group)
test1
8, Ganso (non-modifiable)
()
The other is basically the same as the list.
9, Dictionary (unordered)
{}
Create a dictionary
person = {"Name": "Mr.wu", ' Age ': 18} or person = Dict ({"Name": "Mr.wu", ' Age ': 18})
DIC = { 1:{ 'name':'Aaron','Sex':'Mans',' Age': 18}, 2:{'name':'Alex','Sex':'Mans',' Age': 28}}dic[1]['name'] ='ABC'dic[1]['Job'] ='IT'dic[1].pop ('Sex') v= Dic.get (1) Dic2= {3:{'name':'CBA',' Age': 18}}dic.update (DIC2)Print(DIC)Print(v) forKeyinchDIC:Print(Key,dic[key])
test2
Common operations:
- Indexed-------------------Index
- New-------------------Append Insert
- Delete-------------------Pop del
- Key, value, key-value pairs-------------items
- Loop-------------for key in Dict:print ('%s:%s '% (Key,dict[key]))
- Length-------------len
Summary of data operations:
Data OperationsArithmetic operations:
Comparison operation:
Assignment operation:
Logical operation:
Member Operations:
Identity operation:
Bit operations:
Operator Precedence:
The Day2 of Python