Python3 endswith() Method
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
- suffix -- this parameter can be a string or an element.
- start -- the starting position in the string.
- end -- the ending position in the string.
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
=
'
!!
'
(
Str
.
endswith
(
suffix
)
)
(
Str
.
endswith
(
suffix
,
20
)
)
suffix
=
'
run
'
(
Str
.
endswith
(
suffix
)
)
(
Str
.
endswith
(
suffix
,
0
,
19
)
)
The output of the above example is:
True
True
False
False
Python3 Strings