Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python - String endswith() Method



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 the 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.

Return Value

Returns True if the string ends with the specified value, else returns False.

Example:

In the example below, endswith() method is 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))

The output of the above code will be:

True
True

❮ Python String Methods

5