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.
string.endswith(value)
Example of the Python string endswith() method
#Example 1 text = "python is a programming language" #check the text ends with language or not. print(text.endswith("language")) #output : True
#Example 2 text = "python3" #check the text ends with 3 or not. print(text.endswith("3")) #output: True #Exmaple 3 message = "cyber fauz" msg = message.endswith("uz") print(msg) #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) print(msg)
Related Posts
- startswith() Method in Python
- split() Method in Python
- replace() Method in Python
- isalnum() Method in Python
- islower() Method in Python
- swapcase() Method in Python
- Python string join() Method
- Python string isdigit() Method