🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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()?

  1. A.To close the file
  2. B.Each line ends with a newline character, and strip() removes it
  3. C.To convert the line to a number
  4. 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 →