On This Page

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

Q1 | Which of the following are the modes of both writing and reading in binary format in file?
  • wb+
  • w
  • wb
  • w+
Q2 | Which of the following is not a valid mode to open a file?
  • ab
  • rw
  • r+
  • w+
Q3 | 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
Q4 | How do you get the name of a file from a file object (fp)?
  • fp.name
  • fp.file(name)
  • self.    name    (fp)
  • fp.    name    ()
Q5 | Which of the following is not a valid attribute of a file object (fp)?
  • fp.name
  • fp.closed
  • fp.mode
  • fp.size
Q6 | How do you close a file object (fp)?
  • close(fp)
  • fclose(fp)
  • fp.close()
  • fp.    close    ()
Q7 | How do you get the current position within the file?
  • fp.seek()
  • fp.tell()
  • fp.loc
  • fp.pos
Q8 | 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)
Q9 | How do you delete a file?
  • del(fp)
  • fp.delete()
  • os.remove(‘file’)
  • os.delete(‘file’)
Q10 | 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
Q11 | 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
Q12 | Which function overloads the + operator?
  •     add    ()
  •     plus    ()
  •     sum    ()
  • none of the mentioned
Q13 | Which function overloads the == operator?
  •     eq    ()
  •     equ    ()
  •     isequal    ()
  • none of the mentioned
Q14 | Which operator is overloaded by     lg    ()?
  • <
  • >
  • !=
  • none of the mentioned
Q15 | Which function overloads the >> operator?
  •     more    ()
  •     gt    ()
  •     ge    ()
  • none of the mentioned
Q16 | 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    ()
Q17 | Which function overloads the // operator?
  •     div    ()
  •     ceildiv    ()
  •     floordiv    ()
  •     truediv    ()
Q18 | How many except statements can a try- except block have?
  • zero
  • one
  • more than one
  • more than zero
Q19 | 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
Q20 | k = foo() print(k)
  • 1
  • 2
  • 3
  • error, there is more than one return statement in a single try-finally block
Q21 | What happens when ‘1’ == 1 is executed?
  • we get a true
  • we get a false
  • an typeerror occurs
  • a valueerror occurs
Q22 | g=f(8) print(next(g))
  • 8
  • 9
  • 7
  • error
Q23 | Which of the following is not an exception handling keyword in Python?
  • try
  • except
  • accept
  • finally
Q24 | )) type(g)
  • class <’loop’>
  • class <‘iteration’>
  • class <’range’>
  • class <’generator’>
Q25 | ]
  • nameerror
  • valueerror
  • indexerror
  • typeerror