Check a String is Space in Python

  • Post category:String

In this article, you will see how to check a string is space in Python. A space string is a string that contains only spaces. The string isspace() method returns True if all characters in the string are spaces, otherwise False.

Step 1: Create a string

str = " "
print("str = ", str)
print("str type = ", type(str))

Step 2: Check if a string is a space

if all(c.isspace() for c in str):
    print("Not Space")


str =   
str type =  <class 'str'>

Free resources to learn advanced skills: AiHints and CodeAllow