Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
61.
What does the
file.seek()
method do?
Answer: Option
Explanation:
file.seek()
moves the file cursor to a specified position.
62.
How can you read and print the last 10 lines from a file named "log.txt"?
Answer: Option
Explanation:
Using list slicing to get the last 10 lines and printing them.
63.
What is the purpose of the
file.writelines()
method?
Answer: Option
Explanation:
file.writelines()
writes a list of strings to a file.
64.
How can you create a new text file named "new_file.txt" and write the text "Hello, World!" to it?
Answer: Option
Explanation:
Using a context manager to open the file and writing the text to it.
65.
How can you check if a file named "data.csv" is a valid CSV file?
Answer: Option
Explanation:
Checking if a file has a CSV extension to determine if it's a valid CSV file.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers