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 String isnumeric()
Python String zfill()
Python List
Python String capitalize()
Python Set isdisjoint()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python format()
Python Program to Find HCF or GCD
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Custom Exceptions
Python Program to Concatenate Two Lists
Python abs()
Python help()
Python Program to Catch Multiple Exceptions in One Line
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Find the Factorial of a Number
Python Program to Split a List Into Evenly Sized Chunks
Python filter()
Python String ljust()
Convert String to Byte Array and Reverse in Java
Python Program to Iterate Over Dictionaries Using for Loop
Java String Conversions
Python setattr()
Python Set copy()
Generate a String
Python Program to Shuffle Deck of Cards
Python String rsplit()
Python String istitle()
String Processing with Apache Commons Lang 3
Python List pop()
Python String startswith()
Python Anonymous / Lambda Function