Python .isspace()
Published Oct 3, 2023
Contribute to Docs
The .isspace() string method takes in a string and returns True if the entire string is composed of whitespace characters, otherwise False.
Whitespace characters include:
- Space (‘ ‘)
- Horizontal tab (‘\t’)
- Newline (‘\n’)
- Vertical tab (‘\v’)
Syntax
some_str.isspace()
some_str is the string being checked for whitespace.
Example
The example below uses .isspace() to evaluate the string txt:
txt = " Welcome "x = txt.isspace()print(x)
The output will look like this:
False
Codebyte Example
The following example is runnable and checks if my_string consists entirely of whitespace characters:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Learn to analyze and visualize data using Python and statistics.
- Includes 8 Courses
- With Certificate
- Intermediate.13 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours