Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
86.
How can you read and print the first 5 characters from a file named "sample.txt"?
Answer: Option
Explanation:
Using
file.read(5) to read the first 5 characters.
87.
What does the
os.path.abspath() function do?
Answer: Option
Explanation:
os.path.abspath() returns the absolute path of the current working directory.
88.
How can you write a list of strings to a text file named "output.txt" in Python, with each string on a new line?
Answer: Option
Explanation:
Using
"\n".join(strings) to join the strings with newline characters.
89.
What does the
shutil.rmtree() function do?
Answer: Option
Explanation:
shutil.rmtree() removes a directory and its contents.
90.
What does the
file.writelines() method do?
Answer: Option
Explanation:
file.writelines() writes multiple lines to the file from a list.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers