🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Python Strings: all 15 questions

Quiz: Python Strings · Question 14 of 15

Which code checks that a file name ends with ".pdf"?

Which code checks that a file name ends with ".pdf"?

  1. A.name.find(".pdf") == 0
  2. B.name[-3:] == ".pdf"
  3. C.name.startswith(".pdf")
  4. D.name.endswith(".pdf")
Answer & explanation

Correct answer: name.endswith(".pdf")

endswith() checks the end of the string. name[-3:] has only 3 characters, but ".pdf" has 4.

Can you get the rest right without peeking?

Take the timed Quiz: Python Strings quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →