Python string endswith() Method

In this tutorial, We will see the python string endswith() method with examples.

endswith() Method

The endswith() method is one of the methods in a python string. Python string endswith() method checks whether the string is ending with a particular string(suffix) or not.

  • Return True, if the string ends with a particular value.
  • Return False, If the string does not end with a particular value.
Syntax of Python string startswith() method

This is the syntax of the python string endswith() method.

Example of the Python string endswith() method
#Example 1 

text = "python is a programming language"
#check the text ends with language or not.  
#output : True
#Example 2

text = "python3"
#check the text ends with 3 or not. 

#output: True

#Exmaple 3

message = "cyber fauz"
msg = message.endswith("uz")

#output: True
Related Program

Take a sentence from the user and take a word from the user. Check whether the sentence is ending from the given word of the user or not.

message = input("Enter sentence")
word = input("Enter Word")
msg = message.endswith(word)

Related Posts