The isspace method
The isspace method checks if a string contains only spaces. In addition to spaces, the method recognizes the following characters - '\t' (horizontal indent), '\n' (new line), '\v' (vertical indent), '\f' (move down to the next page), '\r' (return to the beginning of the line). Nothing is passed to the method parameters. The method returns the boolean values True or False.
Syntax
pythonstring.isspace()
Example
Let's check that our string consists only of whitespace characters:
pythontxt = ' '
print(txt.isspace())
Result of code execution:
pythonTrue
Example
Now let's say there are other symbols in the line:
pythontxt = 'abc de'
print(txt.isspace())
As a result, we will see an error:
pythonFalse
Example
Let's check if the character '\n' is present in the string:
pythontxt = '\n'
print(txt.isspace())
Result of code execution:
pythonTrue