Top 1000+ Solved Problem Solving and Python Programming MCQ Questions Answer

From 631 to 645 of 820

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

  • d. fp.size

Q. How do you close a file object (fp)?

a. close(fp)

b. fclose(fp)

c. fp.close()

d. fp.    close    ()

  • c. fp.close()

Q. How do you get the current position within the file?

a. fp.seek()

b. fp.tell()

c. fp.loc

d. fp.pos

  • b. fp.tell()

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)

  • b. os.rename(existing_name, new_name)

Q. How do you delete a file?

a. del(fp)

b. fp.delete()

c. os.remove(‘file’)

d. os.delete(‘file’)

  • c. os.remove(‘file’)

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

  • a. fp.seek(offset, 0)

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

  • d. error

Q. Which function overloads the + operator?

a. add    ()

b. plus    ()

c. sum    ()

d. none of the mentioned

  • a.     add    ()

Q. Which function overloads the == operator?

a. eq    ()

b. equ    ()

c. isequal    ()

d. none of the mentioned

  • a.     eq    ()

Q. Which operator is overloaded by     lg    ()?

a. <

b. >

c. !=

d. none of the mentioned

  • d. none of the mentioned

Q. Which function overloads the >> operator?

a. more    ()

b. gt    ()

c. ge    ()

d. none of the mentioned

  • 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    ()

  • a.     add    (),     str    ()

Q. Which function overloads the // operator?

a. div    ()

b. ceildiv    ()

c. floordiv    ()

d. truediv    ()

  • c.     floordiv    ()

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

a. zero

b. one

c. more than one

d. more than zero

  • 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

  • d. always
Subscribe Now

Get All Updates & News