← Quiz: Exceptions and Files: all 15 questions
Quiz: Exceptions and Files · Question 14 of 15
When reading a file line by line, why do we often call line.strip()?
When reading a file line by line, why do we often call line.strip()?
- A.To close the file
- B.Each line ends with a newline character, and strip() removes it
- C.To convert the line to a number
- D.To read the next line
Answer & explanation
Correct answer: Each line ends with a newline character, and strip() removes it
Without strip(), print(line) shows an extra blank line after each line.
Can you get the rest right without peeking?
Take the timed Quiz: Exceptions and Files quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →