Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




isspace( ) FUNCTION


isspace( ) Function


The isspace( ) Function is used to check if all the letters in the String consists of spaces i.e. ' '.


Example :


x = "            "
if x.isspace():
    print("All the letters in the String are spaces")
else:
    print("No! There are some other letters other than spaces")


Output :



  All the letters in the String are spaces

In the above code, we have declared a String "      " that just consists of spaces.


x = "      "

java_Collections

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.


All the letters in the String are spaces

Similarly, let us look at the next example.


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")


Output :



  No! There are some other letters other than spaces

In the above code, we have declared a String "      " that just consists of spaces.


x ="  hello    "

java_Collections

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.


No! There are some other letters other than spaces