हिंदी

Compare and contrast read(), readline() and readlines().

Advertisements
Advertisements

प्रश्न

Compare and contrast read(), readline() and readlines().

अंतर स्पष्ट करें
Advertisements

उत्तर

Basis of Difference read() readline() readlines()
Purpose Reads the complete file or a specified number of characters Reads one line at a time Reads all lines at once
Return value A string A string containing one line A list of strings
Argument Optional size No argument normally required No argument normally required
Memory use May use large memory if the whole file is read Memory efficient May use large memory for large files
End of file Returns an empty string Returns an empty string Returns an empty list

Example: read(10) reads 10 characters, whereas repeated calls to readline() read successive lines.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Data File Handling - EXERCISE [पृष्ठ १४५]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 7 Data File Handling
EXERCISE | Q 4. | पृष्ठ १४५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×