Wednesday, October 1, 2025
HomeLanguagesstring.whitespace in Python

string.whitespace in Python

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("GeeksforLazyroar")


Output:

Hello
     


GeeksforLazyroar

 
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:
RELATED ARTICLES

Most Popular

Dominic
32330 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6816 POSTS0 COMMENTS
Ted Musemwa
7078 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6774 POSTS0 COMMENTS