Class 12 Computer Science File Handling in Python MCQs Set 3

Python File Handling



File Handling in Python MCQ’s Set – 3

Multiple Choice Questions


41. The default file-open mode is ___________.

a) read

b) write

c) append

d) None of these

Answer : a) read

42. Write a command to open a file named “mybio.txt” in write mode?

a) fileobject = open (“mybio.txt”, “w”)

b) fileobject = open(“mybio.txt”)

c) fileobject = open(“mybio.txt”, “r”)

d) None of these

Answer : a) fileobject = open (“mybio.txt”, “w”)

43. Which of the following is not a valid Text file mode?

a) r

b) p

c) w

d) a

Answer : b) p

44. Which of the following is not a valid Text file mode?

a) r+

b) w+

c) wb+

d) a+

Answer : c) wb+

45. Which text file mode , open the file in write mode and allow to add new content in the file with the existing content of file?

a) r

b) p

c) w

d) a

Answer : d) a

46. Identify which one is the not true for ‘a+’ file mode?

a) File is created if does not exist.

b) If file exist, file’s existing data is retained; new data is appended.

c) if file exist, file is truncated.

d) Both reading and writing operations can take place.

Answer : c) if file exist, file is truncated.

47. Identify which one is the not true for ‘w+’ file mode?

a) File is created if does not exist.

b) If file exist, file’s existing data is retained; new data is appended.

c) if file exist, file is truncated.

d) Both reading and writing operations can take place.

Answer : b) if file exist, file’s existing data is retained; new data is appended.

48. Identify which one is the not true for ‘r’ file mode?

a) File is created if does not exist.

b) It is a default file mode.

c) File must exist already

d) Python raise an I/O error, if file does not exist.

Answer : a) File created if does not exist.

49. An open file is closed by calling the ______ method of its file-object.

a) stop()

b) exit()

c) close( )

d) None of these

Answer : c) close()

50. A _____ function breaks the link of file-object and the file on the disk.

a) open()

b) read()

c) close( )

d) write()

Answer : c) close()

51. A _____ function create a link between a file-object and the file on the disk.

a) open()

b) read()

c) close( )

d) write()

Answer : a) open( )

52. Which file mode does not place the cursor (offset) at the beginning of the file?

a) r+ / r

b) w+ / w

c) a+ / a

d) None of these

Answer : c) a+

53. Which file mode place the cursor (offset) at the beginning of the file?

a) r / r+

b) a

c) a+

d) None of these

Answer : a) r / r+

54. Identify the valid statement for closing a file.

a) close(file_object)

b) file_object.close()

c) file_object.close(file_name)

d) None of these

Answer : b) file_object.close()

55. Python provides mainly _______ types of read functions to read from a data file.

a) three

b) four

c) two

d) None of these

Answer : a) three

56. Which read function does not allow to read at most n bytes from a file?

a) readlines()

b) readline()

c) read()

d) None of these

Answer : a) readlines()

57. Which read function does not returns the read bytes in the form of string?

a) read()

b) readline()

c) readlines()

d) None of these

Answer : c) readlines()

58. Which read function returns the read bytes in the form of list?

a) read()

b) readline()

c) readlines()

d) None of these

Answer : c) readlines()

59. file_object.read(20)

How much bytes reads by the above statement?

a) 20 bytes from current cursor position

b) 19 bytes from current cursor position

c) always reads first 20 bytes from the beginning of file.

d) always read first 19 bytes from the beginning of file.

Answer : a) 20 bytes from current position.

60. file_object.read( )

How much bytes reads by the above statement?

a) By default reads only 10 bytes from current cursor position.

b) By default reads only 9 bytes from current cursor position.

c) Reads the entire file.

d) None of these

Answer : c) Reads the entire file.


More MCQ’s are on the way, Refresh your page…

Python File Handling (MCQ’s)


Python Revision Tour – Multiple Choice Questions (MCQ’s)


Python Functions – Working with Functions (MCQ’s)


You cannot copy content of this page

Scroll to Top