Python String endswith() Method

Returns true if the string ends with the specified character or substring. The comparison is case-sensitive.

Syntax

Python
string.endswith(value, start = None, end = None)

Parameters

ParameterDescription
value Required. The string value to search for within the given string
start Optional. The index at which to start searching. The default is None, meaning 0.
end Optional. The index at which to stop searching. The default is None meaning the end of the string.

Example

Python
str = 'The quick brown fox jumped over the lazy dog'
print(str.endswith('dog'))
print(str.endswith('Dog'))

Output

True
False