The isspace()
method in Python is a String Method that returns True if all characters in the string are whitespace characters, such as spaces, tabs, or newlines. Otherwise, it returns False.
Parameter Values
This function does not accept any parameters.Return Values
The isspace()
method returns a bool
indicating if all characters are whitespace.
How to Use isspace()
in Python
Example 1:
The isspace()
method returns True
if all characters in the string are whitespace characters, otherwise it returns False
.
text = ' '
result = text.isspace()
print(result) # Output: True
Example 2:
Example with alphanumeric characters which returns False
.
text = 'Hello World'
result = text.isspace()
print(result) # Output: False
Example 3:
Using isspace()
with a mix of whitespace and tabs.
text = '\t\n'
result = text.isspace()
print(result) # Output: True