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
little exercise : the dictionary sort
Small practice : an odd number on the front, an even number on the back
recursive function
The definition : a function call itself, this function is a recursive function internally.
Exercises in class:
Tower of Hanoi problem
Fibonacci number
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:
Note: Because reading is a form of open, so you can not write something in there
to read and write files
File object's properties:
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
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.
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
operating system details
system environment variables
on route
1. Generate an absolute path
2. determine whether or not an absolute path
3. return the absolute path
on file and directory operations
to create files and delete files
rename the file
to determine whether there is a file or directory
to the directory name and file name separated
separation and file name extension
on a small exercise classes **: ** generate filename
batch file creation
bulk edit extension