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 dict()
Python id()
Python Program to Reverse a Number
Python Program to Generate a Random Number
Python Machine Learning - Sebastian Raschka
Python Program to Get the Full Path of the Current Working Directory
Python max()
Python List insert()
Python list()
Python String title()
Python Program to Find Factorial of Number Using Recursion
Python String isupper()
Python Program to Iterate Over Dictionaries Using for Loop
APIs in Node.js vs Python - A Comparison
JavaScript Methods of RegExp and String
Python RegEx
Python String rsplit()
Python String capitalize()
Check If a String Is Numeric in Java
Python open()
Python eval()
Python Set difference_update()
Python Program to Find Numbers Divisible by Another Number
Java String Conversions
Python sorted()
Python Program to Check if a Number is Positive, Negative or 0
Python Package
Python String isalnum()
Python bytes()
Python Program to Trim Whitespace From a String
Python map()
Python Program to Delete an Element From a Dictionary