English

Differentiate between readline() and readlines().

Advertisements
Advertisements

Question

Differentiate between readline() and readlines().

Distinguish Between
Advertisements

Solution

readline() command enables you to read per line in a content and readlines() command is used to read all the content present in a file at the same time and gives list of that item. The readline method extracts a single line from a file and returns it as a string. The readlines method returns a list of strings containing the contents of the entire file, with each object representing one line of the file. With read, you can also review the full file into a substring.

shaalaa.com
Reading from a Text File in Python
  Is there an error in this question or solution?
Chapter 2: File Handling in Python - Exercise [Page 37]

APPEARS IN

NCERT Computer Science [English] Class 12
Chapter 2 File Handling in Python
Exercise | Q 1. b) | Page 37
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×