I. Review of the course content
1.python Foundation
2. Basic data Type (str|list|dict|tuple)
3. Convert the string "Old man" to Utf-8
s = "old man" ret = bytes (s,encoding= "Utf-8") print (ret) Ret1 = bytes (s,encoding= "GBK") print (RET1) #程序运行结果如下: B ' \xe8\x80\x81\ Xe7\x94\xb7\xe4\xba\xba ' B ' \xc0\xcf\xc4\xd0\xc8\xcb '
4. Small misunderstanding of function
Take a look at the code below and guess what the running result is.
Li = [11,22,33,44,55,]def F1 (ARG): arg.append ($) li = F1 (li) print (LI)
Most people think the return result is [11,22,33,44,55,66], some people think the result is None, pro, what do you think of the results of the run, is one of them, or something else?
#正确的答案是: None
Li = [11,22,33,44,55,]def F1 (ARG): arg.append ()li = F1 (li) print (LI) program run result: None
Some people still do not understand, the result is not what, should be [11,22,33,44,55,66] just right, don't worry, listen to me slowly say, we look at the following section of code:
Li = [11,22,33,44,55,]def F1 (ARG): arg.append ($) return argli = f1 (li) print (LI) program run result:[11, 22, (a)
See here, most people already understand, perhaps still have a small part still not to understand, everybody think, when learning function, if we want to get the execution result of the program, return through the display , if not specified, The default return value of the function is none, and we are going to say Li = F1 (li) of the first code , here is the return result of the program is assigned to Li, and we know that the default return value of the program is None, and then assign its value to Li, So Li's is none, when we do print (LI) to the value of Li printing out, of course, the output is none, now you should know why the last piece of code execution result is none.
Description: This code mainly examines a knowledge point: The default return value of the function is None
5. The return value is False
Common: Empty list: [] empty tuple: () Empty dictionary: {} Empty collection: Set () None number 0 Space ""
6. Read a few topics on the test paper, related knowledge points
- Intersection of sets
- Convert a string to Utf-8
- False
- Built-in functions: any all bool ABS
Second, built-in functions
1.callable (): Determines whether an incoming parameter can be called
#定义一个函数def F1 (): print (123) #定义一个变量s1 = ' Hello ' #判断f1和s1是否可以被调用print (callable (F1)) print (callable (S1)) Program Run Result: TrueFalse
2.CHR () Ord (): Conversion between numbers and letters
#chr: Converts a number to a letter (ASCII) let = Chr #ord: Converts the letter to a number (ASCII) num = ord (' C ') the print (let) print (NUM) program runs the following result: A67
3.random (): Generate random numbers
#random. Randrange (1,10): Randomly generates any number between 1-9
#random. Random (): randomly generates a decimal between 0-1
Import Randomret = Random.randrange (1,10) print (ret) Ret1 = Random.random () print (RET1) program run Result: 80.22612376370730292
4.compile () |eval () |exec ( )
Compile (): compiles the string into Python code, which is then executed by exec ()
The mechanism of its internal implementation: 1. Read the contents of the file through open, and then put it into memory 2.python inside the string----> Compile----> Special Code 3. Execute code s = "Print (123)" R = Compile (s, "<string >, "exec") #编译, compile the string into Python code exec (r) #执行python代码
The third parameter in compile is three: single: one-line execution eval: Converts a string into a Python expression exec: Compiled into the same content as the Python code executes the result as follows: print (123) 123
Eveal (): Executes the function, converts the string to a Python expression, executes it, and obtains the result of the operation, with the default return value
EXEC (): Execute function, receive string or Python code, if Python code executes directly, if string is first converted to Python code to execute
S1 = ' 7+9+8 ' r = eval (S1) print (R) Exec (' 7+9+8 ') program run Result: 24
5.dir () |help ()
dir (): View the properties and methods of a Class help (): View assistance (list): View the detailed properties and methods of the list class the print (list) program executes the following results: [' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __delitem__ ', ' __dir__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __ getattribute__ ', ' __getitem__ ', ' __gt__ ', ' __hash__ ', ' __iadd__ ', ' __imul__ ', ' __init__ ', ' __iter__ ', ' __le__ ', ' __len_ _ ', ' __lt__ ', ' __mul__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __repr__ ', ' __reversed__ ', ' __rmul__ ', ' __ Setattr__ ', ' __setitem__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' append ', ' clear ', ' copy ', ' Count ', ' extend ', ' Index ', ' Insert ', ' pop ', ' remove ', ' reverse ', ' sort ']
6.divmod ()
Divmod (): There are two return values, one is quotient, the other is the remainder
R = Divmod (97,10) print (r) print (R[0]) the print (R[1]) program runs the following results: (9, 7) 97
7.enumerate (): Enumeration
Dic1 = {"Mouse": $, "clothes": $, "shoes": 500}for key in Enumerate (DIC1): The print (key) program runs as follows: (0, ' clothes ') (1, ' Mouse ') (2, ' shoes ')
8.isinstance (): Determines whether an object is an instance of a class
s = [11,22,33]r = Isinstance (s,list) the print (r) program runs with the following result: True
9.filter ()
10.map ()
11.globals () Locals ()
12.hash ()
13.len ()
14.max () |min () |sum ()
15.memoryview (): Classes related to memory address
16.object (): Parent class for all classes
17.pow (): Sub-square, power
18.property (): Features, object-oriented details
19.range ()
20.repr ()
21:reversed (): Invert
22.round (): Rounding
23.set (): Collection
24.slice (): Slice Python3 New
25.sorted (): Sort
26.super (): An object-oriented explanation
27.vars (): Variables available for the current module
28.zip ():
Python Learning Path Basics (fourth article)