Tutorial Study Image

Python isspace()

The isspace() function in python helps to check whether all the characters in the string are whitespace characters or not. The function returns true if the string full of white space characters (tabs, spaces, newline, etc.) else returns false.


string.isspace() 
 

isspace() Parameters:

The isspace() method doesn't take any parameters.

isspace() Return Value

The return value is always a boolean value. If the string is empty the function returns False.

Input Return Value
All white space characters True
At least one non-whitespace character False

Examples of isspace() method in Python

Example 1: How isspace() works in Python?


string = '   \t'
print(string.isspace())

string = ' a '
print(string.isspace())

string = ''
print(string.isspace())
 

Output:


True
False
False

Example 2: How to use isspace() in Python?


string = '\t  \n'
if string.isspace() == True:
  print('String full of whitespace characters')
else:
  print('String contains non-whitespace characters')
  
string = '15+3 = 18'

if string.isspace() == True:
  print('String full of whitespace characters')
else:
  print('String contains non-whitespace characters.')
 

Output:


String full of whitespace characters
String contains non-whitespace characters