Table of Contents
The isspace() method returns True if there are only whitespace characters in the string. If not, it return False.
Characters that are used for spacing are called whitespace characters. For example: tabs, spaces, newline, etc.
The syntax of isspace() is:
string.isspace()
1. isspace() Parameters
isspace() method doesn’t take any parameters.
2. Return Value from isspace()
isspace() method returns:
Trueif all characters in the string are whitespace charactersFalseif the string is empty or contains at least one non-printable character
3. Example 1: Working of isspace()
s = ' \t' print(s.isspace()) s = ' a ' print(s.isspace()) s = '' print(s.isspace())
Output
True False False
4. Example 2: How to use isspace()?
s = '\t \n'
if s.isspace() == True:
print('All whitespace characters')
else:
print('Contains non-whitespace characters')
s = '2+2 = 4'
if s.isspace() == True:
print('All whitespace characters')
else:
print('Contains non-whitespace characters.')
Output
All whitespace characters Contains non-whitespace characters
Related posts:
Python Program to Make a Simple Calculator
Python Errors and Built-in Exceptions
Python String replace()
Python Tuple
Python Program to Solve Quadratic Equation
Python String isupper()
Python Program to Append to a File
Case-Insensitive String Matching in Java
Python locals()
Python Set intersection()
Python Set symmetric_difference()
Python Program to Count the Occurrence of an Item in a List
Python Set clear()
Python Operators
Python List extend()
Python Global Keyword
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Merge Two Dictionaries
Python hash()
Python List reverse()
Python *args and **kwargs
Python Statement, Indentation and Comments
Python Machine Learning Eqution Reference - Sebastian Raschka
Python object()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Get Line Count of a File
Python String isalnum()
Python Decorators
Encode a String to UTF-8 in Java
Deep Learning in Python - LazyProgrammer
Python Dictionary items()
Python Program to Count the Number of Each Vowel