day05 function, file, os module

Anonymous function

Defined : anonymous function refers to a class without defining a subroutine or function identifier. Python lambda syntax definition with anonymous functions, just use the expression without having to declare. (Omitted by standard procedures def function declaration)
syntax for lambda function contains only a statement
lambda function can accept any number of arguments but only returns the value of an expression
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
little exercise : the dictionary sort
Here Insert Picture Description
Here Insert Picture Description

Small practice : an odd number on the front, an even number on the back
Here Insert Picture Description

recursive function

The definition : a function call itself, this function is a recursive function internally.
Exercises in class:
Here Insert Picture Description
Here Insert Picture Description
Tower of Hanoi problem
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Fibonacci number
Here Insert Picture Description
Here Insert Picture Description

file

File operations introduce
a program used during the operation went to great lengths finally calculated the results Imagine if these data are not stored together, and then restart the computer compared to "no place to cry cry." The default data is loaded into memory, the result is saved to memory, the end of the program execution, all of the data release.
Open the file and close
the file open:
Here Insert Picture Description
Here Insert Picture Description
Note: Because reading is a form of open, so you can not write something in there
Here Insert Picture Description
to read and write files
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
File object's properties:

Here Insert Picture Description
Location:
Seek (offset, from) has two parameters:
offset: Offset
from: Direction 0: indicates the beginning of the file; 1: indicates the current position; 2: the end of the file
Here Insert Picture Description
Here Insert Picture Description
close file
method: call close () Close method file. File after use must be closed, because the resource file object will occupy the operating system,
and the operating system the number of files at the same time that can be opened is limited:
Method Two: Python introduced with statement to automatically help us call the close () method:
with statement works
in python with statement on the occasion of access to resources, ensure file reading and writing regardless of whether an error occurs during processing or abnormal will automatically implement the provisions of ( "clean") operations, the release of the resource being accessed, such as a after the shut down automatically, thread lock automatically acquire and release.
Here Insert Picture Description
Here Insert Picture Description

Detailed os module

os, the semantics of the operating system, the processing operating system-related functions, cross-platform. For example, to display all files / delete a file in the current directory / Get File Size ......
** small exercise: ** judging system
Here Insert Picture Description
Here Insert Picture Description
operating system details
Here Insert Picture Description
Here Insert Picture Description
system environment variables
Here Insert Picture Description
Here Insert Picture Description
on route
1. Generate an absolute path
2. determine whether or not an absolute path
3. return the absolute path
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
on file and directory operations
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
to create files and delete files
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
rename the file
Here Insert Picture Description
Here Insert Picture Description
to determine whether there is a file or directory
Here Insert Picture Description
Here Insert Picture Description
to the directory name and file name separated
Here Insert Picture Description
Here Insert Picture Description
separation and file name extension
Here Insert Picture Description
Here Insert Picture Description
on a small exercise classes **: ** generate filename
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
batch file creation
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
bulk edit extension
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43592835/article/details/90705288