Python endswith() method
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
- 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 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!!!
"
;
str
.
endswith
(
suffix
)
;
str
.
endswith
(
suffix
,
20
)
;
suffix
=
"
is
"
;
str
.
endswith
(
suffix
,
2
,
4
)
;
str
.
endswith
(
suffix
,
2
,
6
)
;
The output of the above example is:
True
True
True
False
Python Strings