isspace() String Method in Python with Examples
isspace()
method returns True
if the string is a white space string otherwise it returns False
.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
Example 1: isspace() String Method
message = ' '
if message.isspace():
print('"%s" is white space string.' %(message))
else:
print('"%s" is not white space string.' %(message))
Output
" " is white space string.
Example 2: isspace() String Method
message = ' a '
if message.isspace():
print('"%s" is white space string.' %(message))
else:
print('"%s" is not white space string.' %(message))
Output
" a " is not white space string.
Related String Methods