Home > Article > Backend Development > Detailed explanation of the difference between read, readline and readlines in python
The following editor will bring you a detailed discussion of the differences between python read readline readlines. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.
The file object is created using the open function. The following table lists the differences between the common functions read, readline, and readlines of the file object:
1. Read the specified number of bytes from the file. If size is not given or is negative, read all.
file.read([size])
2. Read the entire line, including the "\n" character.
file.readline([size])
3. Read all lines and return the list, if sizeint> is given; 0, returns rows whose sum totals approximately sizeint bytes. The actual read value may be larger than sizeint because the buffer needs to be filled.
file.readlines([sizeint])
For example:
read
readline
readlines
The above is the detailed content of Detailed explanation of the difference between read, readline and readlines in python. For more information, please follow other related articles on the PHP Chinese website!