The endswith() method returns True if a string ends with the given suffix otherwise returns False.
Syntax :
str.endswith(suffix, start, end)
Parameters :
suffix : Suffix is nothing but a string which 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.
Returns :
It returns True if string ends with the given suffix otherwise returns False.
CODE 1
Python
# Python code shows the working of# .endswith() functiontext = "geeks for geeks."# returns Falseresult = text.endswith('for geeks')print (result)# returns Trueresult = text.endswith('geeks.')print (result)# returns Trueresult = text.endswith('for geeks.')print (result)# returns Trueresult = text.endswith('geeks for geeks.')print (result) |
Output :
False True True True
CODE 2
Python
# Python code shows the working of# .endswith() functiontext = "geeks for geeks."# start parameter: 10result = text.endswith('geeks.', 10)print(result)# Both start and end is provided# start: 10, end: 16 - 1# Returns Falseresult = text.endswith('geeks', 10, 16)print result# returns Trueresult = text.endswith('geeks', 10, 15)print result |
Output :
True True 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.

