Class 12 Computer Science File Handling in Python MCQs Set 4

Python File Handling



File Handling in Python MCQ’s Set – 4

Multiple Choice Questions


61. file_object.readline( )

How much bytes reads by the above statement?

a) reads only one line at a time from the current cursor position

b) reads only 20 bytes from current cursor position.

c) Reads the entire file.

d) None of these

Answer : a) reads only one line at a time from the current cursor position.

62. file_object.readline(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.

63. What types of value returns by read() function?

a) integer

b) list

c) string

d) None of these

Answer : c) string

64. What types of value returns by readline() function?

a) integer

b) list

c) string

d) None of these

Answer : c) string

65. What types of value returns by readlines() function?

a) integer

b) list

c) string

d) None of these

Answer : b) list

Direction ( Q66 – Q73 ) : Answer on the basis of given text file named ‘story.txt’ .

Hello dear students
I hope you are preparing well.
But, you need to do more practice.
All the best.

66. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.read(10)      # Line 1

print(str)
myfile.close()

a) Hello

b) Hello dear

c) Hello dear students

d) None of these

Answer : b) Hello dear

67. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.readline()      # Line 1

print(str)
myfile.close()

a) Hello

b) Hello dear

c) Hello dear students

d) None of these

Answer : c) Hello dear students

68. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.readline(6)      # Line 1
str = myfile.readline()       # Line 2

print(str)
myfile.close()

a) dear students

b) Hello dear

c) Hello dear students

d) None of these

Answer : a) dear students

69. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.readlines()       

print(str)
myfile.close()

a) Hello dear students

I hope you are preparing well.

But, you need to do more practice.

All the best.

b) Hello dear students I hope you are preparing well. But, you need to do more practice. All the best.

c) [‘Hello dear students\n’, ‘I hope you are preparing well.\n’, ‘But, you need to do more practice.\n’, ‘All the best.\n’]

d) None of these

Answer : c) [‘Hello dear students\n’, ‘I hope you are preparing well.\n’, ‘But, you need to do more practice.\n’, ‘All the best.\n’]

70. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.readline(6)      # Line 1
str = myfile.readline()       # Line 2
str = myfile.readline(6)      # Line 3

print(str)
myfile.close()

a) Hello

b) I hope

c) I hope you are preparing well.

d) None of these

Answer : a) dear students

71. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.read()      # Line 1

print(len(str))
myfile.close()

a) 80

b) 21

c) 100

d) None of these

Answer : c) 100

72. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.readlines()      # Line 1

print(len(str))
myfile.close()

a) 2

b) 4

c) 6

d) None of these

Answer : b) 4

73. What is output of the given code ?

myfile = open("story.txt", "r")

str = myfile.readline()      # Line 1

print(len(str.split()))
myfile.close()

a) 1

b) 2

c) 3

d) None of these

Answer : c) 3

74. Which function can be used to write data into the text file?

a) write( )

b) writeline()

c) writelines()

d) Both (a) and (c)

Answer : d) Both (a) and (d)

75. Which function is use to write a ‘string’ into the text file?

a) write( )

b) writeline()

c) writelines()

d) Both (a) and (c)

Answer : a) write( )

76. Which function is use to write a ‘strings in list’ into the text file?

a) write( )

b) writeline()

c) writelines()

d) Both (a) and (c)

Answer : c) writelines( )

77. A file opened in _________ mode retains its previous data while allowing you to add newer data into.

a) write

b) read

c) append

d) Both (a) and (c)

Answer : c) append

78. A file opened in _________ mode overwrites an existing file or creates a non-existing file.

a) write

b) read

c) append

d) Both (a) and (c)

Answer : a) write

79. What types of value returns by write( ) method?

a) integer value

b) string value

c) list value

d) None of these

Answer : a) integer

80. write( ) methods returns ______

a) string written in a file

b) number of characters written in file

c) size of file, in which it write

d) None of these

Answer : b) number of characters written in 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