Class 12 : File Handling Set 2

11.
which of the following statements are true?

a) When you open a file for reading, if file does not exist, an error occurs.
b) When you open a file for writing, if file does not exist, a new file is created.
c) When you open a file for writing, if file exists, then the exisitng file is overwritten.
d) All of the above.

 

12.
To read 5 characters from a file object fobj, the command should be

a) fobj.read()
b) fobj.readline(5)
c) fobj.read(5)
d) fobj.readlines()

 

13.
In file handling what the term ‘r’ and ‘a’ means?

a) read, append
b) append,read
c) write, append
d) append,write

 

14.
What is the difference between r+ and w+?

a) No difference
b) In r+ mode the file pointer is initially places at the beginning of the file and for w+, the pointer is places at the end.
c) In w+ mode the file pointer is initially places at the beginning of the file and for r+, the pointer is places at the end.
d) depends on operating system

 

15.
If a file is opened in writing mode which of the following statements are true?

a) The file must exist on the disk on the specified path.
b) If the file does not exist at the specified path, the file is opened successfully.
c) The file even if at different location on the disk other than the specified path will get opened.
d) Python will create a new file at the specified location if the file does not exist.