Problem Solving and Python Programming: UNIT V: Files, Modules, Packages

Multiple Choice Questions

Files, Modules, Packages | Problem Solving and Python Programming

Engineering Python : UNIT V : Files, Modules, Packages : Anna University Multiple Choice Questions & Answers

Multiple Choice Questions

Q. 1 File objects are used to read and write data to a file on disk.

a. True

b. False

Ans : a. True

 

Q. 2 Which of the following is a binary file mode ?

a. 'b'

b. ‘rb’

c. ‘r’

d. 'w’  

Ans : b. ‘rb’

 

Q. 3 Which function open file in Python ?

a. open()

b. new()

c. read()

d. start()

Ans : a. open()

 

Q. 4 Which mode create a new file if the file does not exist ?

a. write

b. append

c. both a and b

d. None of these

Ans : c. both a and b

 

Q. 5 Which of the following function reads a line at a time?

a. read()

b. readline()

c. readlines()

d. readnewline()

Ans : b. readline()

 

Q. 6 Which of the following function reads all the line and returns in the form of list ?

a. read()

b. readline()

c. readlines()

d. readnewline()

Ans : c. readlines()

 

Q. 7 The relative paths are relative to current working directory denoted as  a dot(.) while the parent directory is denoted with

a. dot

b. two dots

c. colon

d. none of these

Ans : b. two dots

 

Q. 8 To open a file c:\data.txt for writing, we use

a. f = open("c:\data.txt", "w").

b. f = open("c:\\data.txt", "w")

c. f = open(file = "c:\data.txt", "w")

d. f = open(file = "c:\\data.txt", "w")

Ans : b. f = open("c:\\data.txt", "w")

 

Q. 9 Which symbol is used for append mode ?

а. ар

b. a

c. w

d. app

Ans : а. ар

 

Q. 10 Which block lets you test a block of code for errors ?

a. try

b. except

c. finally

d. All of the above

Ans : a. try

 

 Q. 11 What will be the output of the following code ?

try:

print(num)

except:

print("Exception occurred!!!")

a. num

b. Exception occurred!!!

c. Error

d. None of these

Ans : b. Exception occurred!!!

 

Q. 12 How many except statements can a try-except block have ?

a. zero

b. one

c. more than one

d. more than zero

Ans : d. more than zero

 

Q. 13 When is the finally block executed ?

a. when there is no exception

b. when there is an exception

c. only if some condition that has been specified is satisfied

d. always

Ans : d. always

 

Problem Solving and Python Programming: UNIT V: Files, Modules, Packages : Tag: Engineering Python : Files, Modules, Packages | Problem Solving and Python Programming - Multiple Choice Questions