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:
True
if all characters in the string are whitespace charactersFalse
if 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 locals()
Python String maketrans()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Java Program to Permute All Letters of an Input String
Python Program to Get File Creation and Modification Date
Python Program to Copy a File
Python zip()
Python Program to Slice Lists
Python Dictionary fromkeys()
Python __import__()
Python Dictionary values()
Python Program to Catch Multiple Exceptions in One Line
String Processing with Apache Commons Lang 3
Python range()
Python Program to Print Colored Text to the Terminal
Python String join()
Python String rstrip()
Python String startswith()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python hex()
Python Program to Check if a Number is Positive, Negative or 0
Python Machine Learning Eqution Reference - Sebastian Raschka
Python String islower()
Converting a List to String in Java
Python print()
Array to String Conversions
Python input()
Python Program to Convert Bytes to a String
Python Program to Convert Two Lists Into a Dictionary
CharSequence vs. String in Java
Python List clear()
Python Namespace and Scope