This article describes how to use the endswith () method to process strings in Python. it is a basic knowledge in Python. if you need it, you can refer to endswith () to return true, if the string ends with a specified suffix, otherwise, the return value (False) indicates that the matching with an optional restriction starts and ends from 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