Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python String endswith() Method


previous next AddThis Social Bookmark Button


Description:

This method returns True if the string ends with the specified suffix, otherwise return False optionally restricting the matching with the given indices start and end.

Syntax:

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

Parameters:

Here is the detail of parameters:

  • suffix: could be a string or could also be a tuple of suffixes to look for.

  • start : slice begins from here.

  • end : slice ends here.

Return Value:

It returns True if the string ends with the specified suffix, otherwise return 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);

This will produce following result:

True
True
True
False


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names