On This Page

This set of Problem Solving and Python Programming Multiple Choice Questions & Answers (MCQs) focuses on Problem Solving And Python Programming Set 17

Q1 | Which function is used to read all the characters?
  • read()
  • readcharacters()
  • readall()
  • readchar()
Q2 | Which function is used to read single line from file?
  • readline()
  • readlines()
  • readstatement()
  • readfullline()
Q3 | Which function is used to write all the characters?
  • write()
  • writecharacters()
  • writeall()
  • writechar()
Q4 | Which function is used to write a list of string in a file?
  • writeline()
  • writelines()
  • writestatement()
  • writefullline()
Q5 | Which function is used to close a file in python?
  • close()
  • stop()
  • end()
  • closefile()
Q6 | Is it possible to create a text file in python?
  • yes
  • no
  • machine dependent
  • all of the mentioned
Q7 | Which of the following are the modes of both writing and reading in binary format in file?
  • wb+
  • w
  • wb
  • w+
Q8 | Which of the following is not a valid mode to open a file?
  • ab
  • rw
  • r+
  • w+
Q9 | What is the difference between r+ and w+ modes?
  • no difference
  • in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
  • in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
  • depends on the operating system
Q10 | How do you get the name of a file from a file object (fp)?
  • fp.name
  • fp.file(name)
  • self.    name    (fp)
  • fp.    name    ()
Q11 | Which of the following is not a valid attribute of a file object (fp)?
  • fp.name
  • fp.closed
  • fp.mode
  • fp.size
Q12 | How do you close a file object (fp)?
  • close(fp)
  • fclose(fp)
  • fp.close()
  • fp.    close    ()
Q13 | How do you get the current position within the file?
  • fp.seek()
  • fp.tell()
  • fp.loc
  • fp.pos
Q14 | How do you rename a file?
  • fp.name = ‘new_name.txt’
  • os.rename(existing_name, new_name)
  • os.rename(fp, new_name)
  • os.set_name(existing_name, new_name)
Q15 | How do you delete a file?
  • del(fp)
  • fp.delete()
  • os.remove(‘file’)
  • os.delete(‘file’)
Q16 | How do you change the file position to an offset value from the start?
  • fp.seek(offset, 0)
  • fp.seek(offset, 1)
  • fp.seek(offset, 2)
  • none of the mentioned
Q17 | What happens if no arguments are passed to the seek function?
  • file position is set to the start of file
  • file position is set to the end of file
  • file position remains unchanged
  • error
Q18 | Which function overloads the + operator?
  •     add    ()
  •     plus    ()
  •     sum    ()
  • none of the mentioned
Q19 | Which function overloads the == operator?
  •     eq    ()
  •     equ    ()
  •     isequal    ()
  • none of the mentioned
Q20 | Which operator is overloaded by     lg    ()?
  • <
  • >
  • !=
  • none of the mentioned
Q21 | Which function overloads the >> operator?
  •     more    ()
  •     gt    ()
  •     ge    ()
  • none of the mentioned
Q22 | Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
  •     add    (),     str    ()
  •     str    (),     add    ()
  •     sum    (),     str    ()
  •     str    (),     sum    ()
Q23 | Which function overloads the // operator?
  •     div    ()
  •     ceildiv    ()
  •     floordiv    ()
  •     truediv    ()
Q24 | How many except statements can a try- except block have?
  • zero
  • one
  • more than one
  • more than zero
Q25 | When is the finally block executed?
  • when there is no exception
  • when there is an exception
  • only if some condition that has been specified is satisfied
  • always