Test your knowledge of File Handling • 12 Questions
What does the "r" mode do when opening a file?
"r"
What happens if you open a file with "w" mode and the file already exists?
"w"
What does file.read() return?
file.read()
What is the main advantage of using the with statement for file handling?
with
What does file.readlines() return?
file.readlines()
Which mode should you use to add data to the end of an existing file without erasing it?
"a"
"x"
Why do we use line.strip() when reading lines from a file?
line.strip()
What does CSV stand for?
What is the advantage of csv.DictReader over csv.reader?
csv.DictReader
csv.reader
When writing a CSV file, why should you include newline="" in the open() call?
newline=""
What does the write() method return?
write()
What happens if you try to open a non-existent file with "r" mode?