The isspace() method in Python String checks if the string consists of whitespace. In Python, isspace() refers to an inbuilt method used for string handling. It returns True when all the characters in the string consist of whitespace characters, else, It returns False. This function is therefore used for checking whether the argument consists of all the whitespace characters like : ' ' – Space.
Here is the syntax for isspace() method:
str.isspace()
This method returns true when in the string there exist only whitespace characters and there is at least one character, otherwise, it returns false.
The following example shows the usage of isspace() method.
#!/usr/bin/python str = " "; print str.isspace() str = "This is string example....wow!!!"; print str.isspace()
When we run the above program, it produces the following result:
True False
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.