Hello Python:)
Supplemental Details: Python pass-through lists, dictionaries, and so on are address-passing, without a value.
Start with the Chase!
Lambda expression:
Example:
Non-parametric version:
FUN1 = lambda:123
Ret1 = FUN1 ()
Print (RET1)
#输出123
With reference version:
fun2 = Lambda A1, A2:A1 + A2
Ret2 = fun2
Print (Ret2)
#输出 3
Summary: There is no lambda expression that does not affect Python's normal functioning, but with lambda expressions it makes Python look simpler
Python built-in functions (i):
ABS (): Absolute value
All (): passes in an iterative object, looping parameters. Returns true if each element is truth, otherwise false. Example:
Test1 = All ([True, True, False])
Test2 = All ([True, True, True])
Print (Test1, test2)
#输出False True
Details: In python, 0, None, null (empty string, empty list, empty tuple, empty dictionary) are false, others are true
Any (): Returns true as long as one is true.
ASCII (): Passing in an object, this method goes back to the object's class, looking for __repr__ () to get its return value.
Bin (), Oct (), Hex (), int () are binary, octal, 16 binary, decimal, and are used for binary conversions.
BOOL (): To determine the true or FALSE, convert an object to a Boolean value.
Bytes (), ByteArray (): Byte and byte list, remember bytes ("XXX", encoding = ' utf-8 ').
Chr (), Ord (): The CHR function accepts a number and then finds the ASCII code corresponding to the number and returns it. Ord is the reverse.
Callable (): Determines whether an object can be executed.
Divmod (): Example:
Print (Divmod (10,3))
#输出 (3,1)
Eval (): Example:
Print (eval ("1 + 3"))
#输出4
Details: It's worth noting that eval () supports variable form
EXEC (): Used to execute Python code, example:
EXEC ("For I in Range":p rint (i) ")
#输出1, 2,3,4,5,... (10 lines)
Filter (): The parameters are: function, iteration object. Loops iterate over an object, fetching each element, each of which executes as a parameter of the first function. Example:
Fun = Lambda a:true
RET = filter (fun, [11,22,33,44,55])
For I in RET:
Print (i)
#输出11, 22,33,44,55
Map (): Similar to the above:
ret = map (lambda a:a+100, [1,2,3,4,5])
For I in RET:
Print (i)
#输出101, 102,103,104,105
Globals (): Gets all the global variables. There is also the corresponding locals ().
Hash (): The optimization of the data structure, involving the hashing algorithm.
Isinstance (): Determines whether an object is created by a class.
Issubclass (): Determines whether a class is a subclass of a class
Range (): ...
Max (): Takes the maximum value.
POW (): exponential.
Repr (): Same as ASCII (), but ASCII () will give the kanji a translation, repr () will be output as-is
Round (): Rounding
Sorted (): Sort
SUM (): Sum, typically passing in a list of returns and
Zip (): Example:
File operation:
1) Open File
Open (file name, open mode, encoding), the latter two parameters have default values (read-only and Utf-8)
Open mode: (String)
R: Read-only
W: Write-only, nonexistent, create, empty and then write. Not readable
X: Write only, do not exist then create, present error. Not readable
A: Append, does not exist, is created, exists at the end of append, unreadable.
Open mode: (bytes, do not set the encoding Oh!) )
RB: Read-only
WB: Write only (be careful when writing to convert to bytes)
...
2) Operation file
Read ()
Write ()
Seek (): Adjust the position of the pointer
Tell (): Gets the current pointer position
Flush (): Refreshes the buffer inside the file
ReadLine (): reads a row of data
Truncate (): Intercept. Where the pointer is, it intercepts the front of the pointer, deletes it, and relies on the pointer
3) Close the file
A) Close ()
b) with open (file name, open mode) as obj: This code is equivalent to F = open (...), but the difference is that the previous code is no longer close (), and Python will automatically close the file. It is worth noting that the WITH keyword has been able to support the opening of multiple files.
Pythonman (vi)