dir.endswith()
时间: 2024-05-06 18:19:58 浏览: 56
The `endswith()` method is a built-in string method in Python that returns a Boolean value indicating whether a given string ends with a specified suffix.
Syntax:
`string.endswith(suffix, start, end)`
Parameters:
- `suffix` - A string or tuple of suffixes to be checked.
- `start` (optional) - Starting index within the string to start checking for suffix.
- `end` (optional) - Ending index within the string to stop checking for suffix.
Return Value:
- `True` if the string ends with the specified suffix or one of the specified suffixes, `False` otherwise.
Example:
```
dir_name = "/home/myusername/documents"
if dir_name.endswith("documents"):
print("Directory name ends with 'documents'")
else:
print("Directory name does not end with 'documents'")
```
Output:
```
Directory name ends with 'documents'
```
阅读全文