📜  Python中的字符串.whitespace

📅  最后修改于: 2022-05-13 01:55:35.205000             🧑  作者: Mango

Python中的字符串.whitespace

在 Python3 中, string.whitespace是一个预初始化的字符串,用作字符串常量。在Python中, string.whitespace将为字符提供空格、制表符、换行符、回车符、换页符和垂直制表符。

注意:确保导入字符串库函数以使用字符串.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: