Python String endswith() Method
We will discuss how to check if the string ends with the specified value. If it ends with the given value, we return true else false.
By using endswith() Method, we can know if a given string ends with the given suffix.
String endswith() Method in Python
Syntax:
str.endswith(suffix,Start,End)
Suffix: String that needs to be checked.
Start: starting position where suffix will be needed to check in main string.
End: end position+1 where suffix checking should be stopped.
Note:- Start and end are optional parameters and by default they have the values as 0 and -1.
Let’s see the Python Code:
# Python String endswith() Method string = "Code Speedy is good." # returns True output = string.endswith('good.') print (output) # returns False output = string.endswith('good') print (output) # returns True output = string.endswith('Code Speedy is good.') print (output)
Output:
True False True
Also read:
Leave a Reply