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("Space")
else:
print("Not Space")Output:
str =
str type = <class 'str'>
Space
Free resources to learn advanced skills: AiHints and CodeAllow
