Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
whitespace
communitycreator

What is isspace() in Python?

Mahnoor Zaheer

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The isspace() method is a string function in Python that tells whether or not a string has only whitespaces.

Syntax

It is declared as follows:

string.isspace()
The syntax of isspace() method in Python

Parameters

The isspace() method does not take any parameters.

Return value

Its return value is a Boolean, which is True if the string contains whitespaces only. The return value is False if it does not contain whitespaces or if it contains characters apart from whitespaces.

Code

The isspace() function returns True for the string that only contains whitespaces in the examples below. However, it returns’ False’ for the empty string and the string with both characters and whitespaces.

# string with whitespaces only
string = ' '
print(string.isspace())
# string with whitespaces and other characters
string = 'a b c 2 '
print(string.isspace())
# empty string
string = ''
print(string.isspace())
The syntax of isspace() method in Python

RELATED TAGS

python
whitespace
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring