Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python endswith() method

Python endswith() method

Python Strings Python Strings


Description

The Python endswith() method checks whether a string ends with the specified suffix, returning True if it does and False otherwise. The optional parameters "start" and "end" specify the start and end positions of the search.

Syntax

Syntax of the endswith() method:



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

Parameters

Return Value

Returns True if the string contains the specified suffix, otherwise returns False.

Example

The following example demonstrates the endswith() method:

Example (Python 2.0+)

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

)

;

The output of the above example is:



True

True

True

False


Python Strings Python Strings