Python String endswith() Method
Python String endswith()
The endswith()
method checks whether the specified string matches the end of the given string or not.
Example
Output
Syntax
Parameter Values
Value | Type | Explanation |
---|---|---|
value | Required | Specifies the value to check if the string ends with. |
start | Optional | Specifies the index position to start the search. Default value is 0. |
end | Optional | Specifies the index position to end the search. Default value is the length of the given string (txt). |
Return Value
Value | Explanation |
---|---|
True | If the specified string matches the end of the given string. |
False | If the specified string does not matches the end of the given string. |
More Examples
Check if position 2 to 4 ends with the phrase "th":
Note: The endswith()
method will include the start index value but exclude the end index value.
In the following example, the index value of 2(t) and the index value of 3(h) is considered but not the index value of 3 (o).
Example
Output
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.
We are working to cover every Single Concept in Python.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.