Q. Differentiate between:

a) text file and binary file

b) readline() and readlines()

c) write() and writelines()


Answer :-

a = A text file stores data as ASCII/UNICODE characters whereas a binary file stores data in binary format (as it is stored in memory). Internal conversion is required in text file and, hence, it is slower but binary file does not need any translation and so is faster.

b =  The readline() function reads from a file in read mode and returns the next line in the file or a blank string if there are no more lines. (The returned data is of string type.)
The readlines() function also reads from a file in read mode and returns a list of all lines in the file. (The returned data is of list type.)

c = Write() function is used to write only one line while writelines is used to write more than one line which is stored in form of list.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post