dir.endswith()
时间: 2024-05-06 14:19:58 浏览: 13
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'
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)