text.isdigit()
时间: 2024-05-14 22:12:19 浏览: 17
The `isdigit()` method is a built-in string method in Python that returns `True` if all characters in a string are digits (0-9). If the string contains any non-digit characters, it returns `False`.
Example usage:
```
text = "1234"
print(text.isdigit()) # Output: True
text = "1234abc"
print(text.isdigit()) # Output: False
text = "1 2 3 4"
print(text.isdigit()) # Output: False
```
In the first example, `text` contains only digits, so `isdigit()` returns `True`. In the second example, `text` contains non-digit characters ('a', 'b', and 'c'), so `isdigit()` returns `False`. In the third example, `text` contains spaces, which are also non-digit characters, so `isdigit()` returns `False`.
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)