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

Python3 endswith() Method

Python3 endswith() Method

Python3 Strings Python3 Strings


Description

The endswith() method determines whether a string ends with a 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 within the string.

Syntax

Syntax of the endswith() method:


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

Parameters

Return Value

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

Example

The following example demonstrates the endswith() method:

Example

#!/usr/bin/python3

Str

=

'

Runoob example....wow!!!

'

suffix

=

'

!!

'

print

(

Str

.

endswith

(

suffix

)

)

print

(

Str

.

endswith

(

suffix

,

20

)

)

suffix

=

'

run

'

print

(

Str

.

endswith

(

suffix

)

)

print

(

Str

.

endswith

(

suffix

,

0

,

19

)

)

The output of the above example is:


True
True
False
False

Python3 Strings Python3 Strings