Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
11.
In Python, what is the purpose of the
tell() method when working with files?
Answer: Option
Explanation:
The
tell() method returns the current position of the file cursor.
12.
What happens if you open a file using the mode
"a"?
Answer: Option
Explanation:
The
"a" mode opens the file for appending, and the file cursor is positioned at the end.
13.
How can you read and print the first 3 lines of a file named "sample.txt"?
Answer: Option
Explanation:
Using a
for loop with readline() to read and print the first 3 lines.
14.
What does the
flush() method do when working with files?
Answer: Option
Explanation:
The
flush() method ensures that any buffered data is written to the file.
15.
How can you copy the contents of one file, "source.txt", to another file, "destination.txt"?
Answer: Option
Explanation:
Opening both files and using
write() to copy the contents from source to destination.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers