logo

Python String Endswith() Method


Show

Description

The endswith() method of Python String returns True if the string tends to end with the specified suffix, else it returns False that optionally restricts the matching with the provided indices start and end.

Syntax

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

Parameters

  • suffix - This could be a string or could also be a tuple of suffixes to look for.
  • start - The slice begins from here.
  • end - The slice ends here.

Return Value

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

Example

#!/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)

Result

True
True
True
False

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.