Python str.endswith() function
In Python, the str.endswith()
method is used to check whether a string ends with a specified substring. This method returns True
if the string ends with the specified substring and False
otherwise.
Syntax
- suffix: A string or a tuple of strings to check against the end of the string.
- start (optional): The starting index from which to check the suffix. If omitted, the check starts from the beginning of the string.
- end (optional): The ending index up to which to check the suffix. If omitted, the check goes to the end of the string.
Example Usage
- Basic usage:
- Using start and end parameters:
- Checking multiple suffixes:
Summary
- Use
str.endswith()
to determine if a string ends with a specific substring. - It can check for multiple suffixes and allows for optional starting and ending indices to refine the check.