Files Q&a
Files Q&a
Ans: A bunch of bytes / data stores on some storage device referred by the filename.
Ans: A text file stores data as ASCII/UNICODE characters where as a binary file stores data in
binary format (as it is stored in memory). Internal conversion is required in text file and hence
slower but binary file does not need any translation and faster.
Q.5 Name the methods used for reading and writing data from text file.
Ans: read( ), readline( ), readlines( ) for reading data from file and write( ), writelines( ) to write
data to a file
r+ , rb+ : read and write, w+, wb+ , a+ , ab+ : write/append and read
Ans: When a file is closed data from buffer gets written onto the file on the disk and link from file
is removed. It ensures that data is saved in the file.
12 | P a g e
Q.9 Write a python code to find the size of the file in bytes, number of lines and number of
words.
Ans : stdin represent standard input device and stdout represent standard output device which
are represented as files.
***
13 | P a g e