How to Use the endswith () method to process strings in Python, pythonendswith
The endswith () method returns true. If the string ends with a specified suffix, otherwise, the return value is (False: the matching with an optional restriction starts and ends with the given index ).
Syntax
The following is the syntax of the endswith () method:
Str. endswith (suffix [, start [, end])
Parameters
- Suffix -- this may be a string or a tuples used to find the suffix.
- Start -- slice starts from
- End -- slice till now
Return Value
Returns true if the string ends with the specified suffix. Otherwise, false is returned.
Example
The following example shows how to use the endswith () method.
#! /Usr/bin/pythonstr = "this is string example... wow !!! "; Suffix =" wow !!! "; Print str. endswith (suffix); print str. endswith (suffix, 20); suffix = "is"; print str. endswith (suffix, 2, 4); print str. endswith (suffix, 2, 6 );
When we run the above program, it will produce the following results:
TrueTrueTrueFalse