What is ReadLine () python? ReadLine () Python Definition and usage parsing

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.