0% found this document useful (0 votes)
14 views6 pages

Python File Handling MCQs

Qr paper

Uploaded by

Sam Devan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

Python File Handling MCQs

Qr paper

Uploaded by

Sam Devan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

FILES MCQs

Q1. Which of the following commands is used to open a file “c:\temp.txt” in append-mode?

a. outfile - open(“c:/temp.txt”, “a”)


b. outfile - open(“c:\\temp.txt”, “rw”)
c. outfile - open(“c:\temp.txt”, “w+”)
d. outfile - open(“c:\\temp.txt”, “r+”)

Q2 What are the binary files used for?

a. It is used to store data in the form of bytes.


b. To store data
c. To look folder good
d. None of these

Q3. What is the function of `rb` mode in binary?

a. Both reading and writing operations can take place.


b. File is in only write mode.
c. File is created if it does not exist.
d. File must exist otherwise error will be shown.
Q4. What is the description of `r+b` in binary mode?

a. read and write


b. write and read
c. read only
d. none of these

5. What is binary file mode for append?

a. `rb`
b. `wb`
c. `ab`
d. None of these

Q6. What is the binary file mode associated with “ file must exist, otherwise error will be raised
and reading and writing can take place”.

a. read and write


b. write and read
c. read only
d. append
Q7. What is the process of converting a byte stream back to the original structure called?

a. append
b. txt.file
c. Unpickling
d. None of these.

Q8. Which module is used to store data into python objects with their structure?
a. pickle
b. binary files
c. unpickle
d. None of these

Q9. What is pickle.dump()?


a. dump() function is used to store the object data to the file.
b. It is used to read
c. append
d. None of these

Q10. Which one of the following is the correct statement?

a. pickle import
b. import - pickle
c. import pickle
d. None of the above
Q11. Which is the valid syntax to write an object onto a binary file opened in the write mode?

a. pickle.dump(<object to be written>, <file handle of open file>)


b. pickle.dump(<file handle of open file>, <object to be written>)
c. dump.pickle(<object>, <file handle>)
d. None of the above

Q12. Which method is used for object serialization?

a. Pickling
b. Unpickling
c. None of the above
d. All of the above

Q13. Which method of pickle module is used to read from a binary file?

a. dump()
b. load()
c. All of the above
d. None of the above
Q14.Which method is used for object deserialization?

a. Pickling
b. Unpickling
c. All of the above
d. None of the above
Q15.Which of the following is the correct syntax to read from a file using load function?

a. pickle.load(<filehandle>)
b. <object> - load.pickle(<filehandle>)
c. <object> - pickle.load(<filehandle>)
d. All of the above

Q16. Which method of pickle module is used to write onto a binary file?
a. dump()
b. load()
c. All of the above
d. None of the above

Q17. Which of the following file modes open a file for reading and writing both in the binary
file?
a. r
b. rb
c. rwb
d. rb+

Q18.Which of the following file modes that opens a file for reading and writing both
and overwrites the existing file if the file exists otherwise creates a new file ?

a. w
b. wb+
c. rwb
d. rb

Q19. Which of the following file modes opens a file for appending and reading in a binary file
and moves the files pointer at the end of the file if the file already exists or creates a new file?

a. .a
b. .a+
c. .ab+
d. .ab

Q20.Which of the following file modes will not delete the existing data in binary file?

a. .wb
b. .w
c. .a
d. .ab
ANSWER KEY

1-A 6-A 11-A 16-A

2-A 7-C 12-A 17-D

3-D 8-A 13-B 18-B

4-A 9-A 14-B 19-C

5-C 10-C 15-C 20-D

CSV FILES

Q1 is a file format which stores records separated by comma.


a. .tsv
b. .csv
c. .py
d. .bin

Q2.The CSV files can be operated by software.


a. Spreadsheet
b. Notepad
c. MS Excel
d. All of the above

Q3.When you read csv file using csv.reader() function it returns the values in object.

a. dictionary
b. tuple
c. nested list
d. sets

Q4.CSV module allows to write multiple rows using function.

a. writerows( )
b. writerow( )
c. writer( )
d. None of the above

Q5.Which of the following parameter needs to be added with open function to avoid blank row followed file
each row in CSV file?

a. delimiter
b. newline
c. writer, delimiter
d. file object
Q6.which is the correct way to import a csv module?

a. import csv
b. from csv import *
c. None of the above
d. Both A & B

Q7.Observe the following code and fill the blank in statement1


import csv
with as f: #statement1
r = csv. (f) #statement2
for row in : #statement3
print( ) #statement4

a. open("data.csv")
b. f=open("data.csv")
c. Both A & B are Correct
d. Both A & B are incorrect

Q8.Observe the following code and fill the blank in statement2

import csv

with as f: #statement1

r = csv. (f) #statement2

for row in : #statement3

print( ) #statement4

a. load
b. read()
c. reader()
d. readlines()

Q9.Observe the following code and fill the blank in statement3

import csv

with as f: #statement1

r = csv. (f) #statement2

for row in : #statement3

print( ) #statement4

a. f
b. r
c. r,f
d. None of the above
Q10.Observe the following code and fill the blank in statement4

import csv

with as f: #statement1

r = csv. (f) #statement2

for row in : #statement3

print( ) #statement4

a. r
b. row
c. f
d. csv

You might also like