Python String isspace() Method

The isspace() method returns True if all the characters of the given string are whitespaces. It returns False even if one character is not whitespace.

One or more spaces, tab are called whitespace character.

Syntax:

str.isspace()

Parameters:

None

Return Value:

Returns True if all are whitespace, else returns False.

The following example demonstrates the isspace() method in the interactive shell:

Example: isspace()
>>> mystr = ' '
>>> str.isspace()
True
>>> mystr = '     '
>>> str.isspace()
True
>>> mystr = '\t\t'
>>> str.isspace()
True
>>> mystr = '\n\r'
>>> str.isspace()
True

The isspace() method will return False even if one character is not a whitespace, as shown below.

Example: isspace()
>>> mystr = 'HelloWorld'
>>> str.isspace()
False
>>> mystr = 'Hello World'
>>> str.isspace()
False
>>> mystr = '   h'
>>> str.isspace()
False
>>> mystr = '#\t'
>>> str.isspace()
False
Want to check how much you know Python?