Python File Handling
- Class 12 Computer Science File Handling in Python MCQs Set 1
- Class 12 Computer Science File Handling in Python MCQs Set 2
- Class 12 Computer Science File Handling in Python MCQs Set 3
- Class 12 Computer Science File Handling in Python MCQs Set 4
- Class 12 Computer Science File Handling in Python MCQs Set 5
- Class 12 Computer Science File Handling in Python MCQs Set 6
- Class 12 Computer Science File Handling in Python MCQs Set 7
- Class 12 Computer Science File Handling in Python MCQs Set 8
- Class 12 Computer Science File Handling in Python MCQs Set 9
File Handling in Python MCQ’s Set – 5
Multiple Choice Questions
81. Find the output of the given code .
myfile = open("sample.txt", "w")
t = myfile.write("anjeev")
print(t)
myfile.close()
a) anjeev
b) 6
c) six
d) None of these
82. Find the output of the given code .
myfile = open("sample.txt", "w")
t = myfile.write(23456)
print(t)
myfile.close()
a) 23456
b) 5
c) Error
d) None of these
83. Find the output of the given code .
myfile = open("sample.txt", "w")
t = myfile.write(str(23456))
print(t)
myfile.close()
a) 23456
b) 5
c) Error
d) None of these
84. write( ) function actually writes data onto a ________.
a) memory
b) file
c) buffer
d) None of these
85. ________ method is use to clear the buffer and write contents in buffer to the file.
a) flush()
b) clear()
c) close()
d) None of these
86. When the ______ method is executed, the contents from this buffer are moved to the file located on the permanent storage.
a) flush()
b) clear()
c) close()
d) None of these
87. The ______ method allows the programmers can forcefully write to the file as and when required.
a) flush()
b) clear()
c) close()
d) None of these
88. Which function can be use to remove leading and trailing whitespaces like spaces, tabs, newline characters.
a) strip()
b) rstrip()
c) lstrip()
d) All of these
89. Which method is use to write multiple strings to a file.
a) write()
b) writelines()
c) writeline()
d) None of these
90. Does a writelines() method return the number of characters written in the file?
a) Yes
b) No
91. Find the output of the given code?
myfile = open("sample.txt", "w")
t = myfile.writelines(("mycstutorial", "site"))
print(t)
myfile.close()
a) 16
b) Null
c) None
d) None of these
92. What is the content of file “sample.txt”, after execution of the given code?
myfile = open("sample.txt", "w")
myfile.writelines(["mycstutorial", "is", "the", "best", "site"])
myfile.flush()
myfile.close()
a) mycstutorialisthebestsite
b) mycstutorial is the best site
c) mycstutorial
is
the
best
site
d) None of these
93. What is the content of file “sample.txt”, after execution of the given code?
myfile = open("sample.txt", "w")
myfile.writelines(["mycstutorial\n", "is\n", "the\n", "best\n", "site"])
myfile.flush()
myfile.close()
a) mycstutorialisthebestsite
b) mycstutorial is the best site
c) mycstutorial
is
the
best
site
d) None of these
94. Which function in Python, returns the current position of the file object in the file?
a) seek( )
b) tell()
c) get()
d) None of these
95. tell() function returns _____ type of value.
a) integer
b) float
c) string
d) None of these
96. Which function in Python, is used to position the file object at a particular position in a file?
a) seek( )
b) tell()
c) get()
d) None of these
97. tell( ) function returns the current position from the _______ of the file.
a) end
b) middle
c) beginning
d) None of these
98. Find the output of the given code?
myfile = open("story.txt", "r")
myfile.read(4)
print(myfile.tell())
myfile.close()
a) 4
b) 5
c) None
d) None of these
99. Identify the valid function call statement of seek() method.
a) seek(0)
b) file_object.seek(24, 0)
c) file_object.seek()
d) None of these
100. Find the output of the given code?
myfile = file("story.txt", "r")
myfile.read(4)
myfile.seek(10,1)
print(myfile.tell())
myfile.close()
a) 4
b) 10
c)14
d) None of these
Python File Handling (MCQ’s)
- Class 12 Computer Science File Handling in Python MCQs Set 1
- Class 12 Computer Science File Handling in Python MCQs Set 2
- Class 12 Computer Science File Handling in Python MCQs Set 3
- Class 12 Computer Science File Handling in Python MCQs Set 4
- Class 12 Computer Science File Handling in Python MCQs Set 5
- Class 12 Computer Science File Handling in Python MCQs Set 6
- Class 12 Computer Science File Handling in Python MCQs Set 7
- Class 12 Computer Science File Handling in Python MCQs Set 8
- Class 12 Computer Science File Handling in Python MCQs Set 9
Python Revision Tour – Multiple Choice Questions (MCQ’s)
- Class 12 Computer Science MCQs Python Revision Tour Set – 1
- Class 12 Computer Science MCQs Python Revision Tour Set – 2
Python Functions – Working with Functions (MCQ’s)
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 1
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 2
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 3
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 4
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 5
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 6
Thanks for visiting. Online Classes are available.