How to check if a string is space, tab or newline (empty) in Python

1 Answer

0 votes
import string  
 
s = " "
if s.isspace():
    print("yes")
else:
    print("no")
     
 
s = "\n"
if s.isspace():
    print("yes")
else:
    print("no")

     
s = "\t"
if s.isspace():
    print("yes")
else:
    print("no")
  
  
s = ""
if s.isspace():
    print("yes")
else:
    print("no")
    
    
s = "        ."
if s.isspace():
    print("yes")
else:
    print("no")
    
    
    
'''
run:
  
yes
yes
yes
no
no
 
'''

 



answered May 17, 2019 by avibootz
...