Latest web development tutorials

Python endswith () method

Python strings Python strings


description

Python endswith () method is used to determine whether a string ends with the specified suffix, if end with the specified suffix returns True, otherwise False. Optional parameters "start" and "end" for the start and end position of the search string.

grammar

endswith () method syntax:

str.endswith(suffix[, start[, end]])

parameter

  • suffix - The parameter can be a string or an element.
  • start - the start position of the string.
  • end - the end position of the characters.

return value

If the string contains the specified suffix returns True, otherwise False.

Examples

The following example shows endswith () instance method:

#!/usr/bin/python

str = "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);

Examples of the above output results are as follows:

True
True
True
False

Python strings Python strings