← 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"?
- A.name.find(".pdf") == 0
- B.name[-3:] == ".pdf"
- C.name.startswith(".pdf")
- 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 →