Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
91.
How can you read and print the last 3 lines from a file named "data.txt"?
Answer: Option
Explanation:
Using
lines[-3:]
to get the last 3 lines from the list of lines.
92.
What does the
file.seek()
method do?
Answer: Option
Explanation:
file.seek()
moves the file cursor to a specified position.
93.
How can you check if a file named "output.txt" is writable?
Answer: Option
Explanation:
Using
os.access()
with the os.W_OK
flag to check if the file is writable.
94.
What is the purpose of the
file.mode
attribute?
Answer: Option
Explanation:
file.mode
represents the file's access mode.
95.
How can you write a dictionary to a JSON file named "data.json"?
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