Menu Close

Python String isspace() Method

python string isspace

In this article, you will learn about the python string isspace() method. Python string isspace function is used to return True if all the characters in the string are whitespace otherwise return False.

In previous tutorial, we have seen Python string isprintable method.

Python String isspace() Method:

isspace function in Python is a built-in string function that returns True if all the characters in the string are whitespaces otherwise return False.

Syntax

The syntax of isspace function in python method is:-

string.isspace()

Parameter

isspace function in python does not support any parameter.

Return Type

isspace function in Python returns True or False.

Python string isspace Example:

Here will take some examples to understand Python string isspace() method.

Example 1:

str = " "
str2 = str.isspace()
print(str2)

Output will be:- True

Example 2:

str = "\t \n \r"
str2 = str.isspace()
print(str2)

Output will be:- True

Example 3:

str = "\tPython programming\n"
str2 = str.isspace()
print(str2)

Output will be:- True

Example 4:

Conclusion:str = "  "
if str.isspace():
    print('The String contains spaces.')
else:
    print('The String can not contains space.')

Output

The string contains spaces.

Conclusion

In this tutorial, you have learned the isspace function in python to check that a string contains all whitespace characters or not. If a string contains all whitespace characters, It will return True otherwise return False.

I hope this tutorial will help you. if you like this article, please share it with your friends who want to learn Python programming.

For More Information:- Click Here

Python String isprintable() Method
Python String istitle() Method

Related Posts