Python3 endswith() Method
Description
The endswith() method is used to check whether a string ends with a specified suffix. If it ends with the specified suffix, it returns True; otherwise, it returns False. The optional parameters "start" and "end" specify the starting and ending positions for the string 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 ends with the specified suffix; otherwise, returns False.
Example
The following example demonstrates the use of the endswith() method:
Example
#!/usr/bin/python3
Str='Example 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
Other Extensions
Python3 Strings