Skip to content
Related Articles

Related Articles

string.whitespace in Python
  • Last Updated : 15 Oct, 2019
GeeksforGeeks - Summer Carnival Banner

In Python3, string.whitespace is a pre-initialized string used as string constant. In Python, string.whitespace will give the characters space, tab, linefeed, return, formfeed, and vertical tab.

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.

Note : Make sure to import string library function inorder to use string.whitespace



Code #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")
Output:
Hello
     


Geeksforgeeks

 
Code #2 : Given code tests for the whitespace values.




# 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)
Output:
printable Value is:  
printable Value is:  
printable Value is:  
printable Value is:  
printable Value is:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :