Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
56.
What does the
os.path.join()
function do?
Answer: Option
Explanation:
os.path.join()
joins two paths into a single path.
57.
How can you read and print the lines with odd line numbers from a file named "numbers.txt"?
Answer: Option
Explanation:
Using the index to identify odd line numbers and printing corresponding lines.
58.
What is the purpose of the
file.truncate()
method?
Answer: Option
Explanation:
file.truncate()
truncates the file at the current position.
59.
How can you write a dictionary to a JSON file named "config.json"?
Answer: Option
Explanation:
Using
open()
in write mode and json.dump()
to write a dictionary to a JSON file.
60.
How can you remove a file named "data.txt"?
Answer: Option
Explanation:
Using
os.remove()
to remove a file in Python.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers