Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
21.
What is the purpose of the
os.path.join()
function in Python when working with file paths?
Answer: Option
Explanation:
os.path.join()
is used to concatenate multiple file paths and create a valid path.
22.
How can you read the content of a binary file named "binary_data.dat"?
Answer: Option
Explanation:
To read the content of a binary file, the file should be opened with mode "rb".
23.
What is the purpose of the
shutil.copy()
function?
Answer: Option
Explanation:
shutil.copy()
is used to copy the contents of a file to another location.
24.
How can you read and print only the lines containing the word "Python" from a file named "text.txt"?
Answer: Option
Explanation:
Using a
for
loop to iterate through the lines and printing lines containing "Python".
25.
What does the
os.path.isfile()
function check?
Answer: Option
Explanation:
os.path.isfile()
checks if a path points to a regular file (not a directory).
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers