Worksheets2.2 J277 File handling
Total questions: 23
Worksheet time: 10mins
Mode in the following program to open file for writing in a mode where new data will be added at the end of old data
file =open("poem.txt","__")
r
w
a
r+
Choose the correct statement to close a file stream named myfile:
myfile.terminate()
myfile.end()
myfile.close()
myfile.remove()
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file without erasing old content
Writing into the file by erasing old content
reading from the file without erasing old content
reading from the file by erasing old content
Which function will read a single line at a time?
read()
read(n)
readline()
readlines()
Which memory is volatile memory?
RAM
Hard Disk
CD
Pen drive
Where files are stored permanently?
RAM
Hard Disk
Cache memory
None of these
What is the use of “a” in file handling?
Read
Write
Append
None of the mentioned
_____ function without any argument removes leading and trailing whitespaces.
strip()
lstrip()
rstrip()
trim()
When reading text files, what are the hidden characters typically at the end of each line?
\n
»
#
@
Which is the best type of loop to write a file in?
while loop
for loop
repeat loop
What character is used to comment code out
(a)
Mode in the following program to open file for writing in a mode where new data will be added at the end of old data
file =open("poem.txt","__")
r
a
w
x
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file without erasing old content
Writing into the file by erasing old content
reading from the file without erasing old content
reading from the file by erasing old content
What will happen if you try to open a non-existent file in read mode?
The file is opened as an empty file
The file is opened in append mode
An error is raised
A new file is created
Which of the following modes allows both reading and writing to a file?
r+
w
r
a
What is the correct order of operations for writing data to a file?
Write, open, close
Close, open, write
Open, close, write
Open, write, close
Choose the correct statement to close a file stream named myfile:
myfile.terminate()
myfile.end()
myfile.close()
myfile.remove()
A text file has the file extension of:
.txt
.doc
.text
