Differentiate between: a) text file and binary file b) readline() and readlines() c) write() and writelines()
Text file stores data as a sequence of characters where each line is terminated by an End of Line (EOL) character. The bytes represent ASCII/UNICODE values of characters, making them human readable. Examples include .txt, .py, .csv files.
Binary file consists of data stored as a stream of bytes where bytes do not represent ASCII values of characters. Instead, they represent actual content like images, audio, video, executable files. These files are not human readable and require specific software to read or write.
readline() reads one complete line from a file where lines end with a newline character (\n). It can also read a specified number (n) of bytes but maximum up to the newline character.
readlines() reads all the lines from a file and returns them along with newline characters as a list of strings.
write() takes a string as an argument and writes it to the text file.
writelines() is used to write multiple strings to a file. It requires an iterable object like lists or tuples containing strings as an argument.
Explanation
This question tests understanding of file types and file handling methods in Python. Part (a) requires distinguishing between text files (human-readable, ASCII/UNICODE encoded) and binary files (stream of bytes, not human-readable). Part (b) differentiates between readline() which reads one line at a time, and readlines() which reads all lines into a list. Part (c) distinguishes write() which writes a single string, from writelines() which writes multiple strings from an iterable. The textbook context provides clear definitions for all these concepts.