1. Description of endswith() method

The Python string endswith() method returns True if the string ends with the specified suffix, otherwise returns False, optionally restricting matching with the given start and end indices.

2. Syntax, parameters & Examples

Syntax

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

Parameters

  1. suffix: this is a string or tuple of suffixes to search for.
  2. start: the test starts from this index.
  3. end: end: ends here.

Return value

TRUE if the string ends with the specified suffix, otherwise FALSE.

Example

str = "Python Programming";

suffix = "ing";
print(str.endswith(suffix))
print(str.endswith(suffix,10))

suffix = "gra";
print(str.endswith(suffix, 4, 13))
print(str.endswith(suffix, 2, 10))
"""
attach:
True
True
True
False
"""
Younes Derfoufi
my-courses.net
One thought on “The Python String endswith() method”

Leave a Reply