Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
51.
What is the purpose of the
file.flush()
method?
Answer: Option
Explanation:
file.flush()
writes the buffered data to the file.
52.
How can you append a list of numbers to a binary file named "data.bin"?
Answer: Option
Explanation:
Using
open()
in binary write mode and bytes()
to write a list of numbers to a binary file.
53.
What does the
os.path.splitext()
function return?
Answer: Option
Explanation:
os.path.splitext()
returns the file's extension.
54.
How can you read and print the lines from a file named "book.txt" in reverse order?
Answer: Option
Explanation:
Using
reversed()
to iterate through lines in reverse order.
55.
How can you copy the contents of a file named "source.txt" to another file named "destination.txt"?
Answer: Option
Explanation:
Using a context manager to open both files and writing the content of "source.txt" to "destination.txt".
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers