The isspace()
method is a string function in Python that tells whether or not a string has only whitespaces.
It is declared as follows:
string.isspace()
The isspace()
method does not take any parameters.
Its return value is a Boolean, which is True
if the string contains whitespaces only. The return value is False
if it does not contain whitespaces or if it contains characters apart from whitespaces.
The isspace()
function returns True
for the string that only contains whitespaces in the examples below. However, it returns’ False’ for the empty string and the string with both characters and whitespaces.
# string with whitespaces onlystring = ' 'print(string.isspace())# string with whitespaces and other charactersstring = 'a b c 2 'print(string.isspace())# empty stringstring = ''print(string.isspace())