Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
16.
What is the purpose of the
os.remove()
function?
Answer: Option
Explanation:
The
os.remove()
function is used to delete a file in Python.
17.
How can you read and print only the even-numbered lines from a file named "numbers.txt"?
Answer: Option
Explanation:
Using list slicing to select even-numbered lines and then printing them.
18.
Which method is used to check if a file object is in a valid state?
Answer: Option
Explanation:
The
closed()
method checks if a file object is in a valid state (closed or not).
19.
What is the purpose of the
truncate()
method when working with files?
Answer: Option
Explanation:
The
truncate()
method is used to remove all contents of the file from the current position.
20.
How can you write a dictionary to a file named "data.json" in JSON format?
Answer: Option
Explanation:
Using
json.dump()
to write a dictionary to a JSON file.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers