isprintable在python中的意思_Python字符串isprintable()方法示例
时间: 2023-08-15 14:29:51 浏览: 135
isprintable()是Python中字符串对象的一个内置方法,用于检查字符串是否只包含可打印的字符,返回值为布尔值True或False。如果字符串中只包含可打印字符,则返回True,否则返回False。
以下是isprintable()方法的语法:
```
str.isprintable()
```
示例:
```python
str1 = "Hello World!"
str2 = "你好,世界!"
print(str1.isprintable()) # True
print(str2.isprintable()) # True
# '\n'是不可打印字符,所以返回False
str3 = "Hello\nWorld!"
print(str3.isprintable()) # False
```
阅读全文
相关推荐


















