Python String endswith() Method
Python String endswith() method returns True if a string ends with the given suffix otherwise returns False.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
str.endswith(suffix, start, end)
- suffix: Suffix is nothing but a string that needs to be checked.
- start: Starting position from where suffix is needed to be checked within the string.
- end: Ending position + 1 from where suffix is needed to be checked within the string.
Note: If start and end index is not provided then by default it takes 0 and length -1 as starting and ending indexes where ending index is not included in our search.
It returns True if the string ends with the given suffix otherwise return False.
Example 1: Working of endswith() method Without start and end Parameters
False True True True
Example 2: Working of endswith() method With start and end Parameters
True True False