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 Example

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 from.
end Optional. Integer. Specifies the position to end the search from.

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 Example

Example

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

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

Run Example