Python String isspace
Now, we are going to explore the isspace method. As the name of the method says, the isspace method is used to check if all the characters in the string are whitespaces. So, this method is going to return True, if and only if all the characters in the string are whitespaces, and it returns False otherwise. So, whenever we need to check if all the characters in the string are whitespaces, we can use the isspace method.
Let’s have a look at a simple program, which tries to demonstrate the isspace method.
Python String isspace() Method
As you can see in the above program, we have two strings, in which the first string is not having all the characters as whitespaces, and in the second string, all the characters are whitespaces. So, if we are calling the isspace method on both the strings, the first output that we have is False, and the second output that we have is True. So, you can try executing the above program and observe the output. You can also play with the values for different outputs.
So, as and when required, we can make use of the isspace method, which returns True or False, on the basis of whether or not, all the characters in the string are whitespaces.