Python Files MCQs: MCQs on Files in Python Language

Python Files MCQs. MCQs on Files in Python Programming language.

Python Files MCQs

 

What is the use of truncate() method in file ??

a) truncates the file size
b) deletes the content of the file
c) deletes the file size
d) none of the mentioned

 

The readlines() method returns ??

a) str
b) a list of lines
c) a list of single characters
d) a list of integers

 

Correct syntax of file.readlines() is ??

a) fileObject.readlines( sizehint );
b) fileObject.readlines();
c) fileObject.readlines(sequence)
d) none of the mentioned

 

What is the use of seek() method in files ??

a) sets the file’s current position at the offset
b) sets the file’s previous position at the offset
c) sets the file’s current position within the file
d) none of the mentioned

 

Python Files MCQs

To read the remaining lines of the file from a file object infile we use ??

a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

 

Correct syntax of file.writelines() is ??

a) file.writelines(sequence)
b) fileObject.writelines()
c) fileObject.writelines(sequence)
d) none of the mentioned

 

What will be the output of the following code ??

fo = open(“foo.txt”, “rw+”)
print “Name of the file: “, fo.name

for index in range(5):
line = fo.next()
print “Line No %d – %s” % (index, line)
fo.close()

a) Compilation Error
b) Syntax Error
c) Displays Output
d) None of the mentioned

 

To read the next line of the file from a file object infile we use ??

a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

 

Python Files MCQs

What will be the output of the following ??

fo = open(“foo.txt”, “wb”)
print “Name of the file: “, fo.name
fo.flush()
fo.close()

a) Compilation Error
b) Runtime Error
c) No Output
d) Flushes the file when closing them

 

What is the current syntax of remove() a file ??

a) remove(file_name)
b) remove(new_file_name, current_file_name,)
c) remove(() , file_name))
d) none of the mentioned

 

What will be the output ??

f = None
for i in range (5):
with open(“data.txt”, “w”) as f:
if i > 2:
break
print(f.closed)

a) True
b) False
c) None
d) Error

 

What is the correct syntax of open() function ??

a) file = open(file_name [, access_mode][, buffering])
b) file object = open(file_name [, access_mode][, buffering])
c) file object = open(file_name)
d) none of the mentioned

 

Python Files MCQs

What is the current syntax of rename() a file ??

a) rename(current_file_name, new_file_name)
b) rename(new_file_name, current_file_name,)
c) rename(()(current_file_name, new_file_name))
d) none of the mentioned

 

To read the entire remaining contents of the file as a string from a file object infile we use ??

a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

 

What is unpickling ??

a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned

Read More

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!