Lambda expression:
A lambda expression is also known as an anonymous function, and the general form is:
LAMDBA parameter (, parameter 2 ...): EXECUTE statement
He is equal to
def fuc ( parameters ):
EXECUTE statement
Return Execution Results
The biggest difference between lambda and normal functions is that the subject of a lambda is a single expression, not a block of code, which is why Lambda cannot write multiple lines.
Why use lambda ?
Because he plays the role of a sketch, and its anonymity means you don't need to assign a name to it, it's more concise.
------------------------------------------------ Split Line ---------------------------------------------------- -
Python 's built-in functions
A summary of the contents of the built-in functions:
Below are the terms.
ABS () # to find the absolute value function , return the absolute value of the entry parameter,
#abs (-1) = 1
All () and any ()
All is a logical operation with any, and All is the intersection, any set. That is , all of the arguments are really return 1, any of the entry into the real
#All (1,0) = 0 any (0,1) = 1
ASCII ()
Returns the __repr__ method of an object , and does not know what is used.
Bin (), bool (), float (), int (), Oct (), Hex (), str ()
The above functions are divided into two categories:
The first class is the mathematical type conversion function,Bin (), Oct (), Hex () corresponding to decimal conversion to binary, octal, and octal
The second class is a variable type conversion function,bool (), float (), int (), and STR () corresponding to the conversion to Boolean, float, shape, string type.
Callable (FUC)
Check if incoming parameters can be called and return check results
Chr (i), Ord()
CHR returns the ASCII character corresponding to the integer i , while Ord converts the ASCII character back to I, which isbasically useless.
Classmethod (), Staticmethod ()
These two correspond to class method and static method, haven't learned to leave temporarily empty.
Compile ()
Compiles the incoming string into a python executable statement and returns.
Complex (REAL,IMAG)
This is a method of creating complex numbers, which consists of real and imag .
Delattr (Obj,name), GetAttr (Obj,name), hasattr (obj,name),setattr (obj,name)
These four functions are all methods of manipulating the properties of an object.
Delattr can delete the Name property of the Obj object ,getattr can get the Name property of the Obj object and return it,hasattr is to determine if the Obj object has a Name property and return the result of the decision,SetAttr is the value of the property that sets the obj object.
Dict (), list (), set (), Frozenset (), tuple (),ByteArray ()
The above six functions are functions that create or transform data types.
Dict () is a function created or converted to a dictionary, list () is a function that is created or converted to a list, and set () is a function that is created or converted to a collection, andFrozenset () is the creation of immutable collections . A tuple () is a function that is created or converted to a tuple,ByteArray () is special, and is a function that converts a string to a byte array.
Dir ()
the Dir function returns all the methods in the object in a list.
Divmod (A, B)
Divmod is a tuple-returned result of A/b
#divmod (10,3) = (3,1)
Enumrate ()
The Enumrate is used to iterate through the index-value of the incoming sequence .
Eval (), EXEC ()
Eval can convert an incoming string to an expression execution, andexec () is thesame but different because exec is not actually a function, so the string passed in to exec can be just part of an expression, and The eval must be a complete expression before it can be completed.
Filter (FUC,A), map (fuc,a)
These two function programming tools, the first parameter is the processing way (accepts the function),a is the object to be processed
Filter can return the filter result of a according to FUC requirements
Map will process Each element of a according to fuct requirements.
Zip (A, B)
The zip will return after combining the a sequence with the b sequence.
#a = [A]
#b = [2,4,6]
Print (Zip (b)) =[(2,4), (3,6)]
Globals (), locals ()
Both functions are print module variables,Locals all local variables of the print module, andglobals are all global variables of the print function.
Hash ()
The hash value for the passed-in value.
Help ()
Gets the help command for the incoming function.
ID ()
Gets the memory address of the passed-in value.
Input ()
accepts keyboard input and returns it.
Isinstance (), Issubclass ()
These two functions are judgment functions, one is to judge whether it is an instance, and one is to judge whether it is a subclass.
ITER ()
The ITER function is used to convert the transfer value to an iterative one, that is, the next () method is supported to look for the next value.
Len ()
Gets the character length of the passed-in value.
Max (), Min (), SUM ()
These three are all arithmetic functions,max returns the maximum value of the incoming sequence,min returns the minimum value,sum returns and.
Memoryview ()
This function is a memory-viewing object that returns objects with little application.
Next ()
Returns the next element that iterates over an object while moving the pointer to the next element.
Object ()
Object is not a function, but a base class, and it is best to inherit from object when creating any class .
Open ()
The Open function is shown below.
Pow (A, B)
The POW function is actually the result of returning a**b, useless.
Property ()
At present, the teacher has not said, temporarily left blank.
Range ()
Create a range series of ranges that can be converted to various data types such as list tuples, such as lists (range (1,5)) = [1,2,3,4,5]
Repr ()
The repr function is similar to the STR function, but the repr function is converted to the original form of the string, and str adjusts to a better-read pattern.
Reversed ()
Returns the inverted value of the incoming sequence. reversed ([+]) = [3,2,1]
Round ()
The rounding value of the incoming number.
Slice (start,stop)
You can slice an object without specifying stop. start and stop are character positions.
Sorted ()
Sorts an incoming sequence.
Type ()
Gets the data type of the incoming object.
Super ()
Gets the superclass of the passed-in object.
VARs ()
The VARs function is an upgraded version of the locals function, and the function of the VARs and locals functions is the same when the parameters are not passed in. When you specify a class, you can return only the properties of the specified class.
------------------------------------------------ Split Line --------------------------------------------------
Python file Operations
The previous section didn't see? The Open function is actually a function of the Python operation file.
Python supports the following file operation methods:
A . Basic operating mode
1.R mode 2.w mode 3.a mode 4.x mode
R mode refers to the read mode, when the program opens in R mode, the file can be read and not writable, the file does not exist error.
W mode refers to the write mode, when the program opens in W mode, the file can be written unreadable, write to overwrite, that is, the file pointer at the top, and empty the file, if the file does not exist the creation.
A mode refers to the Append mode, when the program opens in W mode, the file association is unreadable, the Write method is appended, that is, the file pointer at the end, if the file does not exist is created.
x mode is not commonly used.
Two . Binary operation mode
1.RB mode 2.wb mode 3.ab mode 4.xb mode
The above mode is binary read mode, that is, the operation method is consistent, but the read content is not character conversion, preserving the original form.
Three . Extended operation mode
1.r+ mode 2.w+ mode 3.a+ mode 4.x+ mode
The difference between 1.r+ and R mode is that it can be written.
The difference between 2.W + and W mode is that it can be read.
The difference between 3.a+ mode and a is that it can be read.
Python Basics (iii)