C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Python String endswith() MethodPython endswith() method returns true of the string ends with the specified substring, otherwise returns false. Signatureendswith(suffix[, start[, end]]) Parameters
Start and end both parameters are optional. Return TypeIt returns a boolean value either True or False. Let's see some examples to understand the endswith() method. Python String endswith() Method Example 1A simple example which returns true because it ends with dot (.). # Python endswith() function example # Variable declaration str = "Hello this is TheDeveloperBlog." isends = str.endswith(".") # Displaying result print(isends) Output: True Python String endswith() Method Example 2It returns false because string does not end with is. # Python endswith() function example # Variable declaration str = "Hello this is TheDeveloperBlog." isends = str.endswith("is") # Displaying result print(isends) Output: False Python String endswith() Method Example 3Here, we are providing start index of the range from where method starts searching. # Python endswith() function example # Variable declaration str = "Hello this is TheDeveloperBlog." isends = str.endswith("is",10) # Displaying result print(isends) Output: False Python String endswith() Method Example 4It returns true because third parameter stopped the method at index 13. # Python endswith() function example # Variable declaration str = "Hello this is TheDeveloperBlog." isends = str.endswith("is",0,13) # Displaying result print(isends) Output: True
Next TopicPython Strings
|