The isspace( ) Function is used to check if all the letters in the String consists of spaces i.e. ' '.
x = " " if x.isspace(): print("All the letters in the String are spaces") else: print("No! There are some other letters other than spaces")
In the above code, we have declared a String " " that just consists of spaces.
So, to check, if all the letters in the String are spaces, we have used 'isspace( )' function.
if x.isspace(): print("All the letters in the String are spaces") else: print("No! There are some other letters other than spaces")
And in this case, all the letters in the String are spaces. So, we got the below output.
Similarly, let us look at the next example.
x = " hello " if x.isspace(): print("All the letters in the String are spaces") else: print("No! There are some other letters other than spaces")
In the above code, we have declared a String " " that just consists of spaces.
So, to check, if all the letters in the String are spaces, we have used 'isspace( )' function.
x = " hello " if x.isspace(): print("All the letters in the String are spaces") else: print("No! There are some other letters other than spaces")
And in this case, all the letters in the String are not spaces. As there is a String 'hello' along with spaces. So, we got the below output.