Python String endswith() Method

Example

Check if the string ends with the punctuation symbol (.)

txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)

Run Instance

Definition and Usage

If the string ends with the specified value, the endswith() method returns True, otherwise it returns False.

Syntax

string.endswith(value, start, end)

Parameter Value

Parameter Description
value Required. The value to check if the string ends with it.
start Optional. Integer. Specifies the position to start the search.
end Optional. Integer. Specifies the position to end the search.

More Examples

Example

Check if the string ends with the phrase "my world."

txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)

Run Instance

Example

Check if the position 5 to 11 ends with the phrase "my world."

txt = "Hello, welcome to my world."
x = txt.endswith("my world.", 5, 11)
print(x)

Run Instance