Top 1000+ Solved Problem Solving and Python Programming MCQ Questions Answer
Q. Which of the following is not a valid attribute of a file object (fp)?
a. fp.name
b. fp.closed
c. fp.mode
d. fp.size
Q. How do you get the current position within the file?
a. fp.seek()
b. fp.tell()
c. fp.loc
d. fp.pos
Q. How do you rename a file?
a. fp.name = ‘new_name.txt’
b. os.rename(existing_name, new_name)
c. os.rename(fp, new_name)
d. os.set_name(existing_name, new_name)
Q. How do you change the file position to an offset value from the start?
a. fp.seek(offset, 0)
b. fp.seek(offset, 1)
c. fp.seek(offset, 2)
d. none of the mentioned
Q. What happens if no arguments are passed to the seek function?
a. file position is set to the start of file
b. file position is set to the end of file
c. file position remains unchanged
d. error
Q. Which function overloads the == operator?
a. eq ()
b. equ ()
c. isequal ()
d. none of the mentioned
Q. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
a. add (), str ()
b. str (), add ()
c. sum (), str ()
d. str (), sum ()
Q. How many except statements can a try- except block have?
a. zero
b. one
c. more than one
d. more than zero
Q. 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