File Handling Python MCQ
File Handling Python MCQ
1. _______ is a named location on a secondary storage media where data are permanently
stored
a. Memory b. Folder c. File d. Drive
c.File
6. “ The default EOL character in Python is ‘\n’, however other characters like comma,
space can also be used to indicate EOL. “
a. True b. False
c. Depends upon types of text files d. None of these
b. False
7. An image is a type of
a. Text file b. Binary file
c. Executable file d. Csv files
b. Binary file
12. When you try to open a binary file in MS-Word, it will show
a. Actual content b. Garbage values
c. Will not be opened d. Binary digits
b. Garbage values
14. Which of the following extension does not represent a text file?
a. .txt b. .docx c. .csv d. .py
b. docx
20. Raju wants to open ‘exp.txt’ file in read, write and binary mode. Help him in writing
correct code
a. Myobject = open(‘exp.txt’, ‘ab+’) b. Myobject = open(‘exp.txt’, ‘wb+’)
c. Myobject = open(‘exp.txt’, ‘r+’) d. Myobject = open(‘exp.txt’, ‘w+’)
b. Myobject = open(‘exp.txt’, ‘wb+’)
21. If you want to add new line of text in ‘sample.txt’, than which file open mode you would
select?
a. a b. a+ c. w d. both (a) and (b)
d. both (a) and (b)
22. Which of the following is not true regarding ‘w’ file open mode?
a. open files in write mode
b. it replaces old content with new one in existing file
c. if file does not exists, than produces ‘FileNotFound Error’
d. All are true
c. if file does not exists, than produces ‘FileNotFound Error’
23. Which of the following is not true about ‘a’ file open mode?
a. Open files in writing mode
b. If file does not exist, than it creates a new file
c. It places cursor at the beginning of file.
d. It merges new content with existing content of file.
c. It places cursor at the beginning of file.
24. It breaks the link between file object and data file stored in disk
a. EOF b. Close() c. Break d. Dump()
b. Close()
28. Method which returns total number of characters after writing it to the text file
a. Write() b. Writelines() c. Both d. None
a. Write()
30. Suhail wants to write a number 23 into a text file exp.txt. help him in writing suitable
code. (assume that exp.txt is already opened and ‘fileobj’ is file handle)
a. Fileobj.write(23) b. Fileobj.write(‘23’)
c. Both are correct d. None of these
b. Fileobj.write(‘23’)
31. Jorawar wants to add multiple line string as given below in sample.txt.
Techtipnow computer Education and Programming Help him in writing suitable code.
a. Fileobj = open(‘sample.txt’,’w’)
x = [‘techtipnow computer\n’,’education and\n’,’programming\n’]
fileobj.writelines(x)
b. Fileobj = open(‘sample.txt’,’w’)
x = (‘techtipnow computer\n’,’education and\n’,’programming\n’)
fileobj.writelines(x)
c. Both (a) and (b)
d. None of these
c. Both (a) and (b)
32. Gabbar wants to append content in a text file without closing file object. What method
he can choose to do so?
a. Exit() b. Clean() c. Clear() d. Flush()
d. Flush()
33. If you want to read a text file, than it must be opened in
a. r+ mode b. w+ mode c. a+ mode d. All of the above
d. All of the above
35. This method reads one complete line from a file where each line terminates with a
newline (\n) character.
a. Read() b. Readline()
c. Readlines() d. Traverse()
b. Readline()
39. predict the output of given code(assume exp.txt contains ‘techtipnow\n’ as data :
fh = open(‘exp.txt’,’r’)
s = len(fh.read())
print(s)
a. 0 b. 10 c. 11 d. No output
d. No output
40. ____ method is used to position the file object at a particular position in a data file
a. Seek() b. Tell() c. Dump() d. Move()
a. Seek()
42. ______ method is used to convert python objects for writing data in a binary file.
a. Dump() b. Load() c. Seek() d. Write()
a. Dump()
43. Process of transforming data or object in memory (RAM) to a stream of bytes that in a
binary file can be than stored in disk is called
a. Pickling b. Serialization
c. Dumping d. Both (a) and (b)
d. Both (a) and (b)
44. To add and display data for a binary file we can use _________ module
a. Pickle b. Serialize
c. Pandas d. Panther
a. Pickle