Tag: value read-only down position close import FSE Direction Listdir
First, anonymous function
sum=lambda+ arg2 #调用sum函数 print"Value of total : "sum1020 ) #结果为:30 print"Value of total : "sum2020 ) #结果为:40
Application situations
- As an argument to a function
def fun(a, b, opt): print("a =", a) print("b =", b) print("result =", opt(a, b)fun(12lambda+ y #结果为:a = 1 b = 2 result = 3
- As a parameter to the Python built-in function.
= [ {"name":"zhangsan""age":18}, {"name":"lisi""age":19}, {"name":"wangwu""age":17}]#将以上列表按姓名排序。=lambda x:x[‘name‘])
Ii. Documents
Use the Write () function
python file.write(‘12345‘)
- Positioning read/write:
- Gets the location of the current file read: Tell ()
- Navigate to a location: Seek (offset, from)
- Offset: Offsets
- From: direction
- 0: Indicates the beginning of the file
- 1: Indicates the current position
- 2: Indicates end of file
- File Rename: rename ():
import osos.rename(‘test.txt‘‘1.txt‘)os.remove(‘1.txt‘)os.mkdir(‘test‘)os.rmdir(‘test‘)os.getcwd()os.chdir(‘../‘)os.listdir(‘./‘)
python--anonymous functions, file operations