Join Regular Classroom : Visit ClassroomTech

Python String – isspace () method

It is a method in python that checks if the given string has all the characters as whitespaces. It returns True if the condition satisfies else returns False. It returns False of presence of any characters other than a whitespace.

Syntax:

string.isspace()

Example 1:

s = ” “
x = s.isspace()
print(x)

Output:

True

Explanation:

Here the string contains only whitespaces and no other characters. Hence returned True.

Example 2:

s = ” c
x=s.isspace()
print(x)

Output:

False

Explanation:

Here the string has an alphabet i.e. “c” in the middle. Hence it returned False.

Example 3:

s = ” 1
x = s.isspace()
print(x)

Output:

False

Explanation:

Here the string has a digit “1” in between two whitespaces. Hence returned False.

You Missed
Also Checkout