endswith() method in Python String can be used to check whether a given string is ending with a given substring or not.
Like, string “This is Python” is ending with “on” or “n” or “hon” or “Python” etc.
Syntax
mainstring.endswith(sub)
sub: Substring that you want to check.
When a string ends with given substring, method returns True, else it returns False.
s = "This is Python"
print(s.endswith("n")) # returns True
print(s.endswith("on")) # returns True
print(s.endswith("hon")) # returns True
print(s.endswith("thon")) # returns True
print(s.endswith("ython ")) # returns True
That’s all here.
