Python中的字符串.whitespace
在 Python3 中, string.whitespace
是一个预初始化的字符串,用作字符串常量。在Python中, string.whitespace
将为字符提供空格、制表符、换行符、回车符、换页符和垂直制表符。
Syntax : string.whitespace
Parameters : Doesn’t take any parameter, since it’s not a function.
Returns : Return the characters space, tab, linefeed, return, formfeed, and vertical tab.
注意:确保导入字符串库函数以使用字符串.whitespace
代码#1:
# import string library function
import string
print("Hello")
# Storing the characters space, tab etc
result = string.whitespace
# Printing the values
print(result)
print("Geeksforgeeks")
输出:
Hello
Geeksforgeeks
代码#2:给定空白值的代码测试。
# import string library function
import string
# An input string.
Sentence = "Hey, Geeks !, How are you?"
for i in Sentence:
# checking whether the whitespace is present
if i in string.whitespace:
# Printing the whitespace values
print("printable Value is: " + i)
输出:
printable Value is:
printable Value is:
printable Value is:
printable Value is:
printable Value is: