Latest web development tutorials

Python3 endswith () method

Python3 string Python3 string


description

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/python3

Str='w3big example....wow!!!'
suffix='!!'
print (Str.endswith(suffix))
print (Str.endswith(suffix,20))
suffix='run'
print (Str.endswith(suffix))
print (Str.endswith(suffix, 0, 19))

Examples of the above output results are as follows:

True
True
False
False

Python3 string Python3 string