Python - String endswith() Method


Advertisements

The Python string endswith() method is used to check whether the string ends with specified value or not. It returns true when the string ends with specified value, else returns false.

Syntax


string.endswith(value, start, end)

Parameters

value Required. value to check whether the string ends with or not.
start Optional. An integer specifying start position of search. default value is 0.
end Optional. An integer specifying end position of search. default value is end of the string.

Example:

In the below example, endswith() method to used to check whether the string (or a given section of the string) ends with specified value or not.

MyString = "Hello World!"
print(MyString.endswith("World!"))

print(MyString.endswith("World!", 6, 12))

Output

True

True

String Methods
Advertisements