String Endswith in Python
Level 256 keystrokes
This checks if the string ends with '.pdf'. The endswith() method returns True if the string ends with the specified suffix.
Python code
# Create a string representing a filename1filename = "report.pdf"# endswith() checks if the string ends with the given suffix# Returns True because "report.pdf" ends with ".pdf"2print(filename.endswith(".pdf"))Output
True
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
"× 4.× 3(× 2)× 2=× 1