28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

endswith(suffix, beg=0, end=len(string))

Description

The method endswith() 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

Following is the syntax for endswith() method:

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

This method returns True if the string ends with the specified suffix, otherwise return False.

Example

The following example shows the usage of endswith() 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);

Let us compile and run the above program, this will produce the following result:

True

True

True

False

expandtabs(tabsize=8)

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!