In this article, let's look at the python
ReadLine Method, before we enter the article, we first need to know
python readlineWhat it is, its true wording should be readline () python.
ReadLine ()It can be used in Python programming where it can play a role. These things we can all learn in today's article.
Grammar
The ReadLine () method syntax is as follows:
Fileobject.readline ();
Parameters
Size-the number of bytes read from the file.
return value
Returns the bytes read from the string.
Instance
The following example demonstrates the use of the ReadLine () method:
The contents of the file Runoob.txt are as follows:
1:www.runoob.com2:www.runoob.com3:www.runoob.com4:www.runoob.com5:www.runoob.com
To iterate through the contents of a file:
#-*-coding:utf-8-*-# Open File fo = open ("Runoob.txt", "rw+") print "file name:", Fo.nameline = Fo.readline () print "Read first line%s"% ( Line) line = Fo.readline (5) print "Read string:%s"% (line) # Close file Fo.close ()
The result of the above example output is:
The file name is: Runoob.txt read the first line 1:www.runoob.com read the string is: 2:www
In this article, we understand what is the ReadLine () method, do not understand the words in fact, they can try to do, after all, hands-on practice is the best way to verify the learning. Finally, I hope that this article will give you a little help in learning about Python.
For more information, please visit the PHP Chinese Web Python tutorial section.