Review of Python knowledge points (1)

Question 1: What is the function of f.seek(6, 0)?
Answer 1: Offset the pointer of the file object f from the starting position to the position of 6 bytes
. Expansion:

This is a method for file operations in Python, where f is an already opened file object. The first parameter of this method indicates the file offset (offset), that is, the number of bytes moved backward from the starting position of the file, the second parameter indicates the starting position of the offset, and 0 indicates the beginning of the file Position, 1 means the current position, 2 means the end position of the file. Therefore, f.seek(5,0) means to move the file pointer to the position of the beginning of the file plus 5 bytes. If successful, this will cause the next read or write operation to the file to begin at this position in the file.

Question 2: sum = lambda x, y: x + 3*y, what is sum(10, 5) equal to?
Answer 2: 25
expansion:

According to this Lambda expression, the sum function takes two parameters x and y and returns the result of x + 3y. Therefore, substituting sum(10,5) into the Lambda expression for calculation results in:
sum(10, 5) = 10 + 3*5 = 10 + 15 = 25
Therefore, the result of sum(10,5) is 25.

Question 3: a={'name' : 'Li Si'}, the statement to obtain the value of name is
Answer 3: a['name']
expansion:

The statement to obtain the value whose key is 'name' in the dictionary a can be performed by using the index method of the dictionary. The sample code is as follows:

Guess you like

Origin blog.csdn.net/PoGeN1/article/details/131351787