Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
6.
What is the purpose of the
seek() method when working with files?
Answer: Option
Explanation:
The
seek() method is used to move the file cursor to a specified position in the file.
7.
Which of the following modes is used to open a file in Python for both reading and writing?
Answer: Option
Explanation:
The mode
"r+" allows both reading and writing operations on a file.
8.
What does the
readline() method do in Python when working with files?
Answer: Option
Explanation:
The
readline() method is used to read a single line from the file.
9.
How can you write a list of strings to a file named "output.txt"?
Answer: Option
Explanation:
The
writelines() method is used to write a list of strings to a file in Python.
10.
How can you check if a file named "data.txt" exists in a directory using Python?
Answer: Option
Explanation:
The
os.path.exists() function checks if a file exists in a directory.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers